English 中文(简体)
Can NInject load modules/assemblies on demand?
原标题:

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

问题回答

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

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.

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





相关问题
Storing reporting assemblies (.net) in a database

I m developing a project where users need to build reporting queries using complex Linq statements to generate data sets. The best way I could think of to compile these user-generated queries and ...

Sharing components in .NET platform

I have an e-commerce website that is already up and running for some time. It s built on .NET 3.5. So far, so good. The "problem" is that now I need to start sharing functionality (products list, ...

Reference two equal assemblies, only public keys differ

My Visual Studio 2008 project references two (external) assemblies (A+B) both of which happen to be referencing the same third assembly (C). However, assembly A expects assembly C to have a public key ...

热门标签