Can NInject load modules/assemblies on demand?
Asked Answered
A

3

6

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

Ameline answered 7/11, 2009 at 22:20 Comment(1)
I think I don't understand what do you mean. How do you "load services from other assemblies" in Unity?Lashley
K
13

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());
    }
}
Kovar answered 14/11, 2009 at 5:25 Comment(0)
O
3

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.

Ocular answered 25/11, 2009 at 22:10 Comment(4)
Can you please provide more details on how to make Ninject "load NinjectModule classes from assemblies"? Ninject's wiki covers pretty basic stuff.Adaadabel
Ok, I got it now, I mixed Ninject versions in my project.Adaadabel
The provided link to GitHub is broken. Actual link is github.com/ninject/Ninject.Extensions.Conventions.Laureenlaurel
@Laureenlaurel Thanks. Updated.Ocular
S
0

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

Stentor answered 9/11, 2009 at 8:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.