[This is preliminary documentation and subject to change.]
スクリプトを利用して、DependencyInjectionコンテナを生成して コンポーネントを登録し、そのインスタンスを返す
生成されたDependencyInjectionコンテナ
IComponentContainerBuilder.Build
スクリプトにはC#、VBScriptとJScriptが利用できます。スクリプト上の ComponentContainerFactoryAttribute属性をもちIComponentContainerインターフェイス と互換性のある値を返すStaticな関数が、DependencyInjectionコンテナを生成し 依存関係が設定したものを返すファクトリーメソッドとなります。スクリプト上に このファクトリーメソッドが存在しない場合はFactoryNotFoundException例外を 投げます。以下にスクリプトの例をあげます。
[C#]
using System;
using Kodama.DependencyInjection.Container;
using Kodama.DependencyInjection.Factory;
using HogeHoge;
public class ComponentContainerBuilder
{
[ComponentContainerFactory]
public IMutableComponentContainer Build()
{
IMutableComponentContainer container = new ComponentContainerImpl();
container.Register(typeof(ClassA));
container.Register(typeof(ClassB));
return container;
}
}
例外の種類 | 条件 |
---|---|
CompileErrorException | スクリプトのコンパイルエラーが発生した場合はこの例外を投げる |
FactoryNotFoundException | DependencyInjectionコンテナのファクトリーメソッドがスクリプトから みつからない場合はこの例外を投げる |
ScriptComponentContainerBuilder クラス | Kodama.DependencyInjection.Builder 名前空間