2014-11-30 12:22:03 -08:00
|
|
|
|
using Castle.Facilities.TypedFactory;
|
|
|
|
|
using Castle.MicroKernel.Registration;
|
|
|
|
|
using Castle.Windsor;
|
|
|
|
|
using Stylet;
|
|
|
|
|
using System;
|
2015-01-14 04:23:43 -08:00
|
|
|
|
using System.Windows;
|
2014-11-30 12:22:03 -08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrappers
|
|
|
|
|
{
|
2015-01-15 02:06:00 -08:00
|
|
|
|
public class CastleWindsorBootstrapper<TRootViewModel> : BootstrapperBase where TRootViewModel : class
|
2014-11-30 12:22:03 -08:00
|
|
|
|
{
|
|
|
|
|
private IWindsorContainer container;
|
|
|
|
|
|
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 12:22:03 -08:00
|
|
|
|
protected override void ConfigureBootstrapper()
|
|
|
|
|
{
|
|
|
|
|
this.Configure();
|
|
|
|
|
|
|
|
|
|
this.container = new WindsorContainer();
|
|
|
|
|
this.DefaultConfigureIoC(this.container);
|
|
|
|
|
this.ConfigureIoC(this.container);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2015-01-04 05:23:29 -08:00
|
|
|
|
/// Override to configure anything that needs configuring
|
2014-11-30 12:22:03 -08:00
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void Configure() { }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Carries out default configuration of the IoC container. Override if you don't want to do this
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void DefaultConfigureIoC(IWindsorContainer container)
|
|
|
|
|
{
|
|
|
|
|
container.AddFacility<TypedFactoryFacility>();
|
|
|
|
|
container.Register(
|
2014-12-02 04:52:58 -08:00
|
|
|
|
Component.For<IViewManagerConfig>().Instance(this),
|
|
|
|
|
Component.For<IViewManager>().ImplementedBy<ViewManager>().LifestyleSingleton(),
|
2014-11-30 12:22:03 -08:00
|
|
|
|
Component.For<IWindowManager>().ImplementedBy<WindowManager>().LifestyleSingleton(),
|
|
|
|
|
Component.For<IEventAggregator>().ImplementedBy<EventAggregator>().LifestyleSingleton(),
|
|
|
|
|
Component.For<IMessageBoxViewModel>().ImplementedBy<MessageBoxViewModel>().LifestyleTransient()
|
|
|
|
|
);
|
|
|
|
|
foreach (var assembly in this.Assemblies)
|
|
|
|
|
{
|
|
|
|
|
container.Register(Classes.FromAssembly(assembly).Pick().LifestyleTransient());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Override to add your own types to the IoC container.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual void ConfigureIoC(IWindsorContainer container) { }
|
|
|
|
|
|
2014-12-02 07:20:16 -08:00
|
|
|
|
public override object GetInstance(Type type)
|
2014-11-30 12:22:03 -08:00
|
|
|
|
{
|
2014-12-02 04:52:58 -08:00
|
|
|
|
return this.container.Resolve(type);
|
2014-11-30 12:22:03 -08:00
|
|
|
|
}
|
2015-01-14 04:23:43 -08:00
|
|
|
|
|
|
|
|
|
protected override void OnExitInternal(ExitEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.container.Dispose();
|
|
|
|
|
}
|
2014-11-30 12:22:03 -08:00
|
|
|
|
}
|
|
|
|
|
}
|