2015-09-24 33 views
0

我試圖在Ninject中註冊以下等價物,但我有困難(部分原因是來自早期版本簡單注射器的所有更改/棄用)。有人可以確認如何將以下綁定轉換爲Simple Injector?簡單的注射器 - 寄存器相比Ninject中的綁定

this.kernel.Bind(x => x.FromThisAssembly() 
        .SelectAllClasses().InheritedFrom<MyFactory>().BindToSelf() 
        .Configure(b => b.InSingletonScope())); 


this.kernel.Bind(x => x.FromThisAssembly() 
        .SelectAllClasses() 
        .InNamespaceOf<MyClass>().BindToSelf() 
        .Configure(b => b.InSingletonScope())); 

回答

0
container.RegisterCollection(typeof(MyFactory), Assembly.GetExecutingAssembly()); 

var namespaceTypes = 
    from type in Assembly.GetExecutingAssembly().GetTypes() 
    where type.Namespace == typeof(MyClass).Namespace 
    select type; 

foreach (Type type in namespaceTypes) 
    container.Register(type, type, Lifestyle.Singleton); 
+0

謝謝。我有幾個近似的變體,但他們並不完全正確。這些是我需要的。 –