DI StartUp fixes
This commit is contained in:
3
App.xaml
3
App.xaml
@@ -1,8 +1,7 @@
|
|||||||
<Application x:Class="StructureHelper.App"
|
<Application x:Class="StructureHelper.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="clr-namespace:StructureHelper"
|
xmlns:local="clr-namespace:StructureHelper">
|
||||||
StartupUri="Windows/MainWindow/MainView.xaml">
|
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
|||||||
23
App.xaml.cs
23
App.xaml.cs
@@ -11,23 +11,30 @@ namespace StructureHelper
|
|||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
public static IContainer Container { get; private set; }
|
public static IContainer Container { get; private set; }
|
||||||
|
public static ILifetimeScope Scope { get; private set; }
|
||||||
|
|
||||||
protected override void OnStartup(StartupEventArgs e)
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
|
base.OnStartup(e);
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
builder.RegisterType<PrimitiveRepository>().As<IPrimitiveRepository>();
|
builder.RegisterType<PrimitiveRepository>().As<IPrimitiveRepository>().SingleInstance();
|
||||||
builder.RegisterType<PrimitiveService>().As<IPrimitiveService>();
|
builder.RegisterType<PrimitiveService>().As<IPrimitiveService>().SingleInstance();
|
||||||
builder.RegisterType<MainModel>().AsSelf();
|
builder.RegisterType<MainModel>().AsSelf().SingleInstance();
|
||||||
builder.RegisterType<MainViewModel>().AsSelf();
|
builder.RegisterType<MainViewModel>().AsSelf().SingleInstance();
|
||||||
|
|
||||||
builder.RegisterType<MainView>().AsSelf();
|
builder.RegisterType<MainView>().AsSelf();
|
||||||
|
|
||||||
Container = builder.Build();
|
Container = builder.Build();
|
||||||
|
Scope = Container.Resolve<ILifetimeScope>();
|
||||||
|
|
||||||
using (var scope = Container.BeginLifetimeScope())
|
var window = Scope.Resolve<MainView>();
|
||||||
|
window.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnExit(ExitEventArgs e)
|
||||||
{
|
{
|
||||||
var window = scope.Resolve<MainView>();
|
Scope.Dispose();
|
||||||
window.ShowDialog();
|
base.OnExit(e);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user