SimpleContainer dependency injection system implemented
This commit is contained in:
@ -11,14 +11,57 @@ namespace ImageHandlingUI
|
||||
{
|
||||
public class Bootstrapper : BootstrapperBase
|
||||
{
|
||||
// implementing SimpleContainer (dependency injection system in Caliburn micro)
|
||||
private SimpleContainer _container = new SimpleContainer();
|
||||
|
||||
public Bootstrapper()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
// implementing SimpleContainer (dependency injection system in Caliburn micro)
|
||||
//
|
||||
protected override void Configure()
|
||||
{
|
||||
_container.Instance(_container);
|
||||
|
||||
_container
|
||||
.Singleton<IWindowManager, WindowManager>()
|
||||
.Singleton<IEventAggregator, EventAggregator>();
|
||||
|
||||
GetType().Assembly.GetTypes()
|
||||
.Where(type => type.IsClass)
|
||||
.Where(type => type.Name.EndsWith("ViewModel"))
|
||||
.ToList()
|
||||
.ForEach(viewModelType => _container.RegisterPerRequest(
|
||||
viewModelType, viewModelType.ToString(), viewModelType));
|
||||
}
|
||||
//
|
||||
// implementing SimpleContainer (dependency injection system in Caliburn micro)
|
||||
|
||||
protected override void OnStartup(object sender, StartupEventArgs e)
|
||||
{
|
||||
DisplayRootViewFor<ShellViewModel>();
|
||||
}
|
||||
|
||||
// implementing SimpleContainer (dependency injection system in Caliburn micro)
|
||||
//
|
||||
protected override object GetInstance(Type service, string key)
|
||||
{
|
||||
return _container.GetInstance(service, key);
|
||||
}
|
||||
|
||||
protected override IEnumerable<object> GetAllInstances(Type service)
|
||||
{
|
||||
return _container.GetAllInstances(service);
|
||||
}
|
||||
|
||||
protected override void BuildUp(object instance)
|
||||
{
|
||||
_container.BuildUp(instance);
|
||||
}
|
||||
//
|
||||
// implementing SimpleContainer (dependency injection system in Caliburn micro)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user