NinjectBootstrapper - canton7/Stylet GitHub Wiki
This is an example bootstrapper which uses Ninject.
class NinjectBootstrapper : BootstrapperBase<MyRootViewModel>
{
private IKernel kernel;
protected override void Configure()
{
base.Configure();
this.kernel = new StandardKernel();
// These can go into a module
// You must bind IWindowManager and IViewManager
this.kernel.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
this.kernel.Bind<IViewManager>().To<ViewManager>().InSingletonScope();
// IEventAggregator is optional
this.kernel.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();
// MessageBoxViewModel is required to use IWindowManager.ShowMessageBox
this.kernel.Bind<IMessageBoxViewModel>().To<MessageBoxViewModel>(); // Not singleton!
}
protected override object GetInstance(Type service, string key)
{
return string.IsNullOrEmpty(key) ? this.kernel.Get(service) : this.kernel.Get(service, key);
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return this.kernel.GetAll(service);
}
protected override void BuildUp(object instance)
{
this.kernel.Inject(instance);
}
}