NInject 可以按需加载模块/组件吗?
NInject 中是否有设施允许我像在 Unity 中一样按需从其他模块(程序集)加载服务?
Are there facilities in NInject that will allow me to load services from other modules (assemblies) on demand like it's done in Unity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我很确定这就是您正在寻找的:
如果您在 Ninject.dll 中使用反射器查看 KernelBase,您将看到此调用将递归加载已加载程序集中的所有模块(Load 方法采用 IEnumerable)
I'm pretty sure this is what you're looking for:
If you look at KernelBase with reflector in Ninject.dll you will see that this call will recursively load all modules in the loaded assemblies (Load method takes an IEnumerable)
我不太明白你所说的“像 Unity”是什么意思,但你可以做一些不同的事情来加载程序集。默认情况下,Ninject 本身会加载扩展/插件的本地程序集。 Ninject 还可以从程序集中加载 NinjectModule 类。如果你想做一些更复杂的事情,你可以使用 Ninject.Extensions.Conventions项目要做很多不同的扫描和类型装订。
I don't quite understand what you mean by "Like Unity" but you can do a few different things for loading assemblies. Ninject itself will load local assemblies for extensions/plugins by default. Ninject can also load NinjectModule classes from assemblies. If you want to do something more complex, you can use the Ninject.Extensions.Conventions project to do a lot of different scanning and type binding.
如果您指的是开箱即用的非静态加载程序集,那么事实并非如此。
关于此还有很多其他问题,例如在类似架构的插件中使用Ninject< /a>
If you're referring to loading Assemblies non-statically out of the box, no it doesnt.
There are many other questions on this, e.g., Using Ninject in a plugin like architecture