From d7919fbe79854ec99876cb49f6d07c3da74af856 Mon Sep 17 00:00:00 2001 From: Holger Boerchers Date: Mon, 25 Jul 2016 21:37:43 +0200 Subject: [PATCH] Added Autofac --- MaterialModernWPF/App.xaml | 3 +- MaterialModernWPF/App.xaml.cs | 17 +++++---- MaterialModernWPF/Bootstrapper.cs | 25 +++++++++++++ MaterialModernWPF/MaterialModernWPF.csproj | 36 +++++++++++++++---- .../{MainWindow.xaml => Shell.xaml} | 19 +++------- .../{MainWindow.xaml.cs => Shell.xaml.cs} | 4 +-- MaterialModernWPF/packages.config | 5 +++ 7 files changed, 75 insertions(+), 34 deletions(-) create mode 100644 MaterialModernWPF/Bootstrapper.cs rename MaterialModernWPF/{MainWindow.xaml => Shell.xaml} (87%) rename MaterialModernWPF/{MainWindow.xaml.cs => Shell.xaml.cs} (88%) diff --git a/MaterialModernWPF/App.xaml b/MaterialModernWPF/App.xaml index e303cff..bfdb3c5 100644 --- a/MaterialModernWPF/App.xaml +++ b/MaterialModernWPF/App.xaml @@ -1,8 +1,7 @@  + xmlns:local="clr-namespace:MaterialModernWPF"> diff --git a/MaterialModernWPF/App.xaml.cs b/MaterialModernWPF/App.xaml.cs index b120d73..d6da62f 100644 --- a/MaterialModernWPF/App.xaml.cs +++ b/MaterialModernWPF/App.xaml.cs @@ -1,17 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; namespace MaterialModernWPF { /// - /// Interaktionslogik für "App.xaml" + /// Interaktionslogik für "App.xaml" /// public partial class App : Application { + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + new Bootstrapper().Run(); + } } -} +} \ No newline at end of file diff --git a/MaterialModernWPF/Bootstrapper.cs b/MaterialModernWPF/Bootstrapper.cs new file mode 100644 index 0000000..6c2e529 --- /dev/null +++ b/MaterialModernWPF/Bootstrapper.cs @@ -0,0 +1,25 @@ +using System.Windows; +using Autofac; +using Prism.Autofac; + +namespace MaterialModernWPF +{ + public class Bootstrapper : AutofacBootstrapper + { + protected override void ConfigureContainerBuilder(ContainerBuilder builder) + { + base.ConfigureContainerBuilder(builder); + builder.RegisterType(); + //builder.RegisterType(); + } + + protected override DependencyObject CreateShell() => Container.Resolve(); + + protected override void InitializeShell() + { + base.InitializeShell(); + Application.Current.MainWindow = (Window)Shell; + Application.Current.MainWindow.Show(); + } + } +} \ No newline at end of file diff --git a/MaterialModernWPF/MaterialModernWPF.csproj b/MaterialModernWPF/MaterialModernWPF.csproj index bd51b7d..f304254 100644 --- a/MaterialModernWPF/MaterialModernWPF.csproj +++ b/MaterialModernWPF/MaterialModernWPF.csproj @@ -38,6 +38,10 @@ airballoon.ico + + ..\packages\Autofac.3.5.2\lib\net40\Autofac.dll + True + ..\packages\MaterialDesignColors.1.1.3\lib\net45\MaterialDesignColors.dll True @@ -46,12 +50,29 @@ ..\packages\MaterialDesignThemes.2.0.0.638\lib\net45\MaterialDesignThemes.Wpf.dll True + + ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll + True + ..\packages\ModernWpf.Core.2.0.0-alpha94\lib\net40-Client\ModernWpf.Core.dll True + + ..\packages\Prism.Core.6.1.0\lib\net45\Prism.dll + True + + + ..\packages\Prism.Autofac.6.1.1\lib\net45\Prism.Autofac.Wpf.dll + True + + + ..\packages\Prism.Wpf.6.1.0\lib\net45\Prism.Wpf.dll + True + + @@ -70,20 +91,17 @@ MSBuild:Compile Designer - - MSBuild:Compile - Designer - App.xaml Code - - MainWindow.xaml + + Shell.xaml Code + Code @@ -114,6 +132,12 @@ + + + MSBuild:Compile + Designer + +