Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bootstrapper for Caliburn.Micro with Unity as IoC
public class Bootstrapper : BootstrapperBase
{
private IUnityContainer _unityContainer;
#region Constructor
public Bootstrapper()
{
Initialize();
}
#endregion
#region Overrides
protected override void Configure()
{
_unityContainer = new UnityContainer();
_unityContainer.RegisterInstance<IWindowManager>(new WindowManager());
_unityContainer.RegisterInstance<IEventAggregator>(new EventAggregator(), new ContainerControlledLifetimeManager());
//View Models
_unityContainer.RegisterInstance<IShellViewModel>(new ShellViewModel());
}
protected override void BuildUp(object instance)
{
_unityContainer.BuildUp(instance);
base.BuildUp(instance);
}
protected override object GetInstance(Type service, string key)
{
return string.IsNullOrEmpty(key) ? _unityContainer.Resolve(service, key) : _unityContainer.Resolve(service);
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return _unityContainer.ResolveAll(service);
}
protected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<IShellViewModel>();
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment