Can NInject load modules/assemblies on demand?

让人想犯罪 __ 提交于 2019-11-29 10:35:17

问题


Are there facilities in NInject that will allow me to load services from other modules (assemblies) on demand like it's done in Unity?


回答1:


I'm pretty sure this is what you're looking for:

var kernel = new StandardKernel();
kernel.Load( Assembly.Load("yourpath_to_assembly.dll");

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)

public void Load(IEnumerable<Assembly> assemblies)
{
    foreach (Assembly assembly in assemblies)
    {
        this.Load(assembly.GetNinjectModules());
    }
}



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1694640/can-ninject-load-modules-assemblies-on-demand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!