And the winner is... Stylet!

This commit is contained in:
SpoinkyNL committed 2017-12-27 16:50:34 +01:00
1 parent 73241793b8
commit 418b3adea7
24 files changed
+299 -370

No files matched your search

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Ninject;
using Stylet;
namespace Artemis.UI.Stylet
{
public class NinjectBootstrapper<TRootViewModel> : BootstrapperBase where TRootViewModel : class
{
private object _rootViewModel;
private IKernel kernel;
protected virtual object RootViewModel =>
_rootViewModel ?? (_rootViewModel = GetInstance(typeof(TRootViewModel)));
protected override void ConfigureBootstrapper()
{
kernel = new StandardKernel();
DefaultConfigureIoC(kernel);
ConfigureIoC(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)
{
var viewManagerConfig = new ViewManagerConfig
{
ViewFactory = GetInstance,
ViewAssemblies = new List<Assembly> {GetType().Assembly}
};
kernel.Bind<IViewManager>().ToConstant(new ViewManager(viewManagerConfig));
kernel.Bind<IWindowManagerConfig>().ToConstant(this).InTransientScope();
kernel.Bind<IWindowManager>().ToMethod(c => new WindowManager(c.Kernel.Get<IViewManager>(),
() => c.Kernel.Get<IMessageBoxViewModel>(), c.Kernel.Get<IWindowManagerConfig>())).InSingletonScope();
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)
{
}
public override object GetInstance(Type type)
{
return kernel.Get(type);
}
protected override void Launch()
{
DisplayRootView(RootViewModel);
}
public override void Dispose()
{
base.Dispose();
ScreenExtensions.TryDispose(_rootViewModel);
if (kernel != null)
kernel.Dispose();
}
}
}