依存性注入には Ninject を使用します。ドメイン オブジェクトが IThing である、自由形式で解釈される DDD を使用してコードを設計しています。
次のコードでは、IThing インスタンスを使用して IThingControl を取得する方法を教えてください。
interface IThing {}
class Thing : IThing {}
interface IThingControl<T> where T:IThing {}
class ThingControl<Thing> {}
class Module : NinjectModule {
public override void Load() {
Bind<IThingControl<Thing>>().To<ThingControl>();
}
}
class SomewhereInCode {
void AddControls() {
List<IThing> things = new List<IThing> {
new Thing()
};
foreach (IThing thing in things) {
IThingControl<IThing> control = _kernel.Get(); // <----- eh?
this.Controls.Add(control);
}
}
}