Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有任何内置到 Ninject 的方法允许动态实例化任何给定类型的程序集限定名称(无需在 custom 中手动绑定类型NinjectModule)?
NinjectModule
我当然可以使用Activator.CreateInstance,但由于我已经在使用 Ninject,我宁愿坚持使用它而不是使用这种方法(顺便说一下,我听说这可能很慢)。
Activator.CreateInstance
您可以在下面使用,它将查找在给定程序集中扩展 NinjectModule 的所有类并加载它们:
var kernel = new StandardKernel(); kernel.Load(Assembly.Load("assembly.dll"));
Ninject 需要绑定才能创建实例。这些绑定既可以静态创建,也可以使用约定创建。根据您想要做什么,约定可能是您需要的。看看 Ninject.Extensions.Conventions。