Skip to content
Remo Gloor edited this page Jul 17, 2013 · 7 revisions

Introduction

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.

Binaries

Example

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.

Clone this wiki locally