views:

367

answers:

3

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

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., http://stackoverflow.com/questions/330927/using-ninject-in-a-plugin-like-architecture

Ruben Bartelink
A: 

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());
    }
}
Sean Chambers
+2  A: 

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.

Ian Davis
Can you please provide more details on how to make Ninject "load NinjectModule classes from assemblies"?Ninject's wiki covers pretty basic stuff.
Piotr Owsiak
Ok, I got it now, I mixed Ninject versions in my project.
Piotr Owsiak