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