-
Notifications
You must be signed in to change notification settings - Fork 12
Home
Remo Gloor edited this page Jul 17, 2013
·
7 revisions
Sometimes it is necessary to separate parts of the application to avoid duplicated bindings (e.g. Plugins that share interfaces from the main application) or to ensure that some part can not have a side affect to other parts (e.g. to ensure that wrong scoping has no influence). In these cases you can use the Child Kernel extension, which forwards any unknown request to the parent kernel.
- Current release: http://code.google.com/p/ninject2/downloads/list?q=Ninject.Extensions.ChildKernel
- Latest build: https://teamcity.bbv.ch/viewLog.html?buildTypeId=bt23&buildId=lastSuccessful&tab=artifacts
var mainKernel = new StandardKernel();
mainKernel.Bind<SharedService>().ToSelf().InSingletonScope();
var pluginAKernel = new ChildKernel(this.mainKernel);
pluginAKernel.Bind<IPlugin>().To<PluginA>.InSingletonScope();
var pluginBKernel = new ChildKernel(this.mainKernel);
pluginBKernel.Bind<IPlugin>().To<PluginB>.InSingletonScope();
var pluginA = pluginAKernel.Get<IPlugin>();
var pluginB = pluginBKernel.Get<IPlugin>();
PluginA and PluginB are different instances but if they have SharedService as dependency. They’ll both share the instance.