Created
October 14, 2018 06:05
-
-
Save anuviswan/1ff937fd7674c29e95647465a024f22b to your computer and use it in GitHub Desktop.
Bootstrapper for Caliburn.Micro with Unity as IoC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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