Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 209
IgorM Avatar asked Nov 07 '09 22:11

IgorM


2 Answers

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());
    }
}
like image 177
Sean Chambers Avatar answered Oct 12 '22 19:10

Sean Chambers


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.

like image 40
Ian Davis Avatar answered Oct 12 '22 19:10

Ian Davis