2014-11-30 07:57:08 -08:00
|
|
|
|
using Ninject;
|
|
|
|
|
using Stylet;
|
|
|
|
|
using System;
|
2015-01-14 04:23:43 -08:00
|
|
|
|
using System.Windows;
|
2014-11-30 07:57:08 -08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrappers
|
|
|
|
|
{
|
2015-01-15 02:06:00 -08:00
|
|
|
|
public class NinjectBootstrapper<TRootViewModel> : BootstrapperBase where TRootViewModel : class
|
2014-11-30 07:57:08 -08:00
|
|
|
|
{
|
|
|
|
|
private IKernel kernel;
|
|
|
|
|
|
2015-01-15 02:06:00 -08:00
|
|
|
|
private object _rootViewModel;
|
|
|
|
|
protected override object RootViewModel
|
|
|
|
|
{
|
|
|
|
|
get { return this._rootViewModel ?? (this._rootViewModel = this.GetInstance(typeof(TRootViewModel))); }
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 07:57:08 -08:00
|
|
|
|
protected override void ConfigureBootstrapper()
|
|
|
|
|
{
|
|
|
|
|
this.kernel = new StandardKernel();
|
|
|
|
|
this.DefaultConfigureIoC(this.kernel);
|
|
|
|
|
this.ConfigureIoC(this.kernel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Carries out default configuration of the IoC container. Override if you don't want to do this
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void DefaultConfigureIoC(IKernel kernel)
|
|
|
|
|
{
|
2014-12-02 04:52:58 -08:00
|
|
|
|
kernel.Bind<IViewManagerConfig>().ToConstant(this);
|
|
|
|
|
kernel.Bind<IViewManager>().To<ViewManager>().InSingletonScope();
|
2015-03-30 07:02:07 -07:00
|
|
|
|
kernel.Bind<IWindowManagerConfig>().ToConstant(this);
|
|
|
|
|
kernel.Bind<IWindowManager>().ToMethod(c => new WindowManager(c.Kernel.Get<IViewManager>(), () => c.Kernel.Get<IMessageBoxViewModel>(), c.Kernel.Get<IWindowManagerConfig>())).InSingletonScope();
|
2014-11-30 07:57:08 -08:00
|
|
|
|
kernel.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();
|
|
|
|
|
kernel.Bind<IMessageBoxViewModel>().To<MessageBoxViewModel>(); // Not singleton!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Override to add your own types to the IoC container.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void ConfigureIoC(IKernel kernel) { }
|
|
|
|
|
|
2014-12-02 07:20:16 -08:00
|
|
|
|
public override object GetInstance(Type type)
|
2014-11-30 07:57:08 -08:00
|
|
|
|
{
|
2014-12-02 04:52:58 -08:00
|
|
|
|
return this.kernel.Get(type);
|
2014-11-30 07:57:08 -08:00
|
|
|
|
}
|
2015-01-14 04:23:43 -08:00
|
|
|
|
|
2015-02-09 04:39:21 -08:00
|
|
|
|
public override void Dispose()
|
2015-01-14 04:23:43 -08:00
|
|
|
|
{
|
|
|
|
|
this.kernel.Dispose();
|
|
|
|
|
}
|
2014-11-30 07:57:08 -08:00
|
|
|
|
}
|
|
|
|
|
}
|