diff --git a/App.xaml b/App.xaml index 6c920ed..7b2d341 100644 --- a/App.xaml +++ b/App.xaml @@ -1,8 +1,7 @@  + xmlns:local="clr-namespace:StructureHelper"> diff --git a/App.xaml.cs b/App.xaml.cs index 835413f..da89033 100644 --- a/App.xaml.cs +++ b/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().As(); - builder.RegisterType().As(); - builder.RegisterType().AsSelf(); - builder.RegisterType().AsSelf(); + builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); + builder.RegisterType().AsSelf().SingleInstance(); + builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf(); Container = builder.Build(); - - using (var scope = Container.BeginLifetimeScope()) - { - var window = scope.Resolve(); - window.ShowDialog(); - } + Scope = Container.Resolve(); + + var window = Scope.Resolve(); + window.Show(); + } + + protected override void OnExit(ExitEventArgs e) + { + Scope.Dispose(); + base.OnExit(e); } } }