2015-09-24 37 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

谢谢。我有几个近似的变体,但他们并不完全正确。这些是我需要的。 –