与Ninject中的Bind相比,简单的注入器-寄存器

本文关键字:注入器 寄存器 简单 Ninject 中的 Bind 相比 | 更新日期: 2023-09-27 18:14:29

我试图在Ninject中注册以下等同,但我遇到了困难(部分原因是来自早期版本的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()));

与Ninject中的Bind相比,简单的注入器-寄存器

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);