[This is preliminary documentation and subject to change.]
DependencyInjectionコンテナの実装クラスです
この型のすべてのメンバの一覧については、 ComponentContainerImpl メンバを参照してください。
System.Object
Kodama.DependencyInjection.Container.ComponentContainerImpl
この型の public static (Visual Basicでは Shared) のすべてのメンバは、 マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
[C#]
using System;
using Kodama.DependencyInjection.Component;
using Kodama.DependencyInjection.Container;
using Kodama.DependencyInjection.Factory;
using Kodama.Function;
using Kodama.Function.Bind;
using Kodama.Function.Member;
....
public interface IBar
{
void Print();
}
public class BarImpl : IBar
{
public void Print()
{
Console.WriteLine("BarImpl");
}
}
public class Foo
{
private IBar dependency1;
private IBar dependency2;
private int val;
// InjectionPoint属性のついたメソッドは自動的に
// セッターインジェクションのメソッドに設定される
[InjectionPoint]
public void SetDependency1(IBar dep)
{
dependency1 = dep;
}
public void SetDependency2(IBar dep, int v)
{
dependency2 = dep;
val = v;
}
// InitializationPoint属性のついたメソッドは自動的に
// 初期化メソッドに設定される
[InitializationPoint]
public void Initialize1()
{
Console.WriteLine("Init1");
}
public void Initialize2(int v)
{
Console.WriteLine("Init2 val = " + v.ToString());
}
}
...
// 通常はコンテナへのコンポーネントの登録、セッターインジェクション及び
// 初期化メソッドの設定はスクリプトで行う。
// 詳細はKodama.DependencyInjection.Factory.DefaultComponetContainerFactory#Create
// メソッドのオーバーロードを参照。
IMutableComponentContainer container = new ComponentContainerImpl();
continer.Register(typeof(BarImpl));
IComponentEntry entry = new PrototypeComponetEntry(container, typeof(Foo));
// 手動によるセッターインジェクションの設定
entry.AddInjectionFanctor(
new BindFunctor(
new MemberFunctor(typeof(Foo).GetMethod("SetDependency2")),
new NotBoundArgument(0),
new TypedArgumentComponentProvider(container, typeof(IBar)),
1));
// 手動による初期化メソッドの設定
entry.AddInitializationFactor(
new BindFunctor(
new MemberFunctor(typeof(Foo).GetMethod("Initialize2")),
new NotBoundArgument(0),
2));
container.Register(entry);
Foo foo = (Foo)continer.GetComponent(typeof(Foo));
名前空間: Kodama.DependencyInjection.Container
アセンブリ: Kodama.DependencyInjection (Kodama.DependencyInjection.dll 内)
ComponentContainerImpl クラス | ComponentContainerImpl メンバ | Kodama.DependencyInjection.Container 名前空間