共用方式為


ServiceCollection class

ServiceCollection 是一個介面,描述註冊服務的一組方法。 這樣會以較輕的方式模擬 .NET 相依性插入服務集合功能,但實例而非類型除外。

建構函式

ServiceCollection(Record<string, unknown>)

建構提供者實例

方法

addFactory<InstanceType, Dependencies>(string, string[], DependencyFactory<InstanceType, Dependencies, false>)

使用一組相依性註冊金鑰的處理站。

addFactory<InstanceType>(string, Factory<InstanceType, false>)

註冊金鑰的處理站。

addInstance<InstanceType>(string, InstanceType)

依金鑰註冊實例。 這會覆寫現有的實例。

composeFactory<InstanceType, Dependencies>(string, string[], DependencyFactory<InstanceType, Dependencies, true>)

註冊具有一組相依性之索引鍵的處理站(預期未定義的初始值)。

composeFactory<InstanceType>(string, Factory<InstanceType, true>)

註冊索引鍵的處理站(預期未定義的初始值)。

makeInstance<InstanceType>(string, boolean)

建置單一服務。

makeInstances<InstancesType>()

建置完整的服務集。

mustMakeInstance<InstanceType>(string, boolean)

建置單一服務並判斷提示它未定義。

mustMakeInstances<InstancesType>(string[])

建置完整的服務集,判斷提示指定的索引鍵未定義。

建構函式詳細資料

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

所有解析服務