简单注入器 - 在 Ninject 中注册与绑定相比
Simple Injector - Register Compared to Bind in Ninject
我正在尝试在 Ninject 中注册以下等效项,但我遇到了困难(部分原因是早期版本的 Simple Injector 中的所有 changes/deprecation)。有人可以确认以下绑定将如何转换为 Simple Injector 吗?
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()));
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);
我正在尝试在 Ninject 中注册以下等效项,但我遇到了困难(部分原因是早期版本的 Simple Injector 中的所有 changes/deprecation)。有人可以确认以下绑定将如何转换为 Simple Injector 吗?
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()));
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);