ServiceCollection class
ServiceCollection은 서비스를 등록하는 메서드 집합을 설명하는 인터페이스입니다. 이는 형식이 아닌 인스턴스를 제외하고 .NET 종속성 주입 서비스 컬렉션 기능을 더 가볍게 모방합니다.
생성자
| Service |
공급자 인스턴스 생성 |
메서드
| add |
종속성 집합을 사용하여 키에 대한 팩터리를 등록합니다. |
| add |
키에 대한 팩터리를 등록합니다. |
| add |
키로 인스턴스를 등록합니다. 그러면 기존 인스턴스가 덮어씁니다. |
| compose |
종속성 집합을 사용하여 키에 대한 팩터리(정의되지 않은 초기 값이 필요합니다)를 등록합니다. |
| compose |
키에 대한 팩터리(정의되지 않은 초기 값이 필요합니다)를 등록합니다. |
| make |
단일 서비스를 빌드합니다. |
| make |
전체 서비스 집합을 빌드합니다. |
| must |
단일 서비스를 빌드하고 정의되지 않음을 어설션합니다. |
| must |
지정된 키가 정의되지 않음을 어설션하여 전체 서비스 집합을 빌드합니다. |
생성자 세부 정보
ServiceCollection(Record<string, unknown>)
공급자 인스턴스 생성
new ServiceCollection(defaultServices?: Record<string, unknown>)
매개 변수
- defaultServices
-
Record<string, unknown>
기본 서비스 집합
메서드 세부 정보
addFactory<InstanceType, Dependencies>(string, string[], DependencyFactory<InstanceType, Dependencies, false>)
종속성 집합을 사용하여 키에 대한 팩터리를 등록합니다.
function addFactory<InstanceType, Dependencies>(key: string, dependencies: string[], factory: DependencyFactory<InstanceType, Dependencies, false>): this
매개 변수
- key
-
string
팩터리에서 제공할 키
- dependencies
-
string[]
이 인스턴스가 의존하는 항목 집합입니다.
services통해 팩터리 함수에 제공됩니다.
- factory
-
DependencyFactory<InstanceType, Dependencies, false>
제공할 인스턴스를 만드는 함수
반환
this
연결에 대한 이
addFactory<InstanceType>(string, Factory<InstanceType, false>)
키에 대한 팩터리를 등록합니다.
function addFactory<InstanceType>(key: string, factory: Factory<InstanceType, false>): this
매개 변수
- key
-
string
팩터리에서 제공할 키
- factory
-
Factory<InstanceType, false>
제공할 인스턴스를 만드는 함수
반환
this
연결에 대한 이
addInstance<InstanceType>(string, InstanceType)
키로 인스턴스를 등록합니다. 그러면 기존 인스턴스가 덮어씁니다.
function addInstance<InstanceType>(key: string, instance: InstanceType): this
매개 변수
- key
-
string
제공 중인 인스턴스의 키
- instance
-
InstanceType
제공할 인스턴스
반환
this
연결에 대한 이
composeFactory<InstanceType, Dependencies>(string, string[], DependencyFactory<InstanceType, Dependencies, true>)
종속성 집합을 사용하여 키에 대한 팩터리(정의되지 않은 초기 값이 필요합니다)를 등록합니다.
function composeFactory<InstanceType, Dependencies>(key: string, dependencies: string[], factory: DependencyFactory<InstanceType, Dependencies, true>): this
매개 변수
- key
-
string
팩터리에서 제공할 키
- dependencies
-
string[]
이 인스턴스가 의존하는 항목 집합입니다.
services통해 팩터리 함수에 제공됩니다.
- factory
-
DependencyFactory<InstanceType, Dependencies, true>
제공할 인스턴스를 만드는 함수
반환
this
연결에 대한 이
composeFactory<InstanceType>(string, Factory<InstanceType, true>)
키에 대한 팩터리(정의되지 않은 초기 값이 필요합니다)를 등록합니다.
function composeFactory<InstanceType>(key: string, factory: Factory<InstanceType, true>): this
매개 변수
- key
-
string
제공 중인 인스턴스의 키
- factory
-
Factory<InstanceType, true>
반환
this
연결에 대한 이
makeInstance<InstanceType>(string, boolean)
단일 서비스를 빌드합니다.
function makeInstance<InstanceType>(key: string, deep?: boolean): InstanceType | undefined
매개 변수
- key
-
string
빌드할 서비스
- deep
-
boolean
모든 종속성 재구성
반환
InstanceType | undefined
서비스 인스턴스 또는 정의되지 않음
makeInstances<InstancesType>()
전체 서비스 집합을 빌드합니다.
function makeInstances<InstancesType>(): InstancesType
반환
InstancesType
해결된 모든 서비스
mustMakeInstance<InstanceType>(string, boolean)
단일 서비스를 빌드하고 정의되지 않음을 어설션합니다.
function mustMakeInstance<InstanceType>(key: string, deep?: boolean): InstanceType
매개 변수
- key
-
string
빌드할 서비스
- deep
-
boolean
모든 종속성 재구성
반환
InstanceType
서비스 인스턴스
mustMakeInstances<InstancesType>(string[])
지정된 키가 정의되지 않음을 어설션하여 전체 서비스 집합을 빌드합니다.
function mustMakeInstances<InstancesType>(keys: string[]): InstancesType
매개 변수
- keys
-
string[]
정의되지 않아야 하는 인스턴스
반환
InstancesType
모든 해결 서비스