次の方法で共有


ServiceCollection class

ServiceCollection は、サービスを登録する一連のメソッドを記述するインターフェイスです。 これは、より軽い方法で、型ではなくインスタンスを除き、.NET 依存関係挿入サービスのコレクション機能を模倣します。

コンストラクター

ServiceCollection(Record<string, unknown>)

Providers インスタンスを構築する

メソッド

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)

1 つのサービスを構築します。

makeInstances<InstancesType>()

サービスの完全なセットを構築します。

mustMakeInstance<InstanceType>(string, boolean)

1 つのサービスをビルドし、未定義ではないことをアサートします。

mustMakeInstances<InstancesType>(string[])

指定したキーが未定義ではないことをアサートして、サービスの完全なセットを構築します。

コンストラクターの詳細

ServiceCollection(Record<string, unknown>)

Providers インスタンスを構築する

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)

1 つのサービスを構築します。

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)

1 つのサービスをビルドし、未定義ではないことをアサートします。

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

すべての解決サービス