using Ninject; using Stylet; using System; using System.Windows; namespace Bootstrappers { public class NinjectBootstrapper : BootstrapperBase where TRootViewModel : class { private IKernel kernel; private object _rootViewModel; protected override object RootViewModel { get { return this._rootViewModel ?? (this._rootViewModel = this.GetInstance(typeof(TRootViewModel))); } } protected override void ConfigureBootstrapper() { this.Configure(); this.kernel = new StandardKernel(); this.DefaultConfigureIoC(this.kernel); this.ConfigureIoC(this.kernel); } /// /// Override to configure anything that needs configuring /// protected virtual void Configure() { } /// /// Carries out default configuration of the IoC container. Override if you don't want to do this /// protected virtual void DefaultConfigureIoC(IKernel kernel) { kernel.Bind().ToConstant(this); kernel.Bind().To().InSingletonScope(); kernel.Bind().ToMethod(c => new WindowManager(c.Kernel.Get(), () => c.Kernel.Get())).InSingletonScope(); kernel.Bind().To().InSingletonScope(); kernel.Bind().To(); // Not singleton! } /// /// Override to add your own types to the IoC container. /// protected virtual void ConfigureIoC(IKernel kernel) { } public override object GetInstance(Type type) { return this.kernel.Get(type); } public override void Dispose() { this.kernel.Dispose(); } } }