I have couple of class libraries in my project and all are using Ninject IoC container. I wanted to load all the modules in a StandardKernel at one go wherever an INinjectModule is found. So I used:
var kernel = new StandardKernel();
kernel.Load(AppDomain.CurrentDomain.GetAssemblies())
But this doesn’t work for some reason. Can anyone help?
Well, this often happens when bindings are declared but other modules are loaded where that module tries to resolve a binding which has not loaded yet. This happens because
List<INinjectModule>may not in the right order.If you think this is the case. Follow this resolution.
The idea is we will have a
bootstapperfor each assembly, where the bootstrapper will be responsible to load the modules in its logical order.Let us consider an interface for bootstrapper (this we will use to find the bootstrapper in an assembly)
Now consider for your DataAccess assembly, implement the
INinjectModuleBootstrapper:This is how you defne the
Bootstrapperfor all your assembly. Now, from your program startup, we need theStandardKernelwhere all the modules are loaded. We will write something like this:And our
BootstrapperHelperclass is: