Skip to content

Instantly share code, notes, and snippets.

@anuviswan
Created October 14, 2018 06:05
Show Gist options
  • Save anuviswan/1ff937fd7674c29e95647465a024f22b to your computer and use it in GitHub Desktop.
Save anuviswan/1ff937fd7674c29e95647465a024f22b to your computer and use it in GitHub Desktop.
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