Commits

Christian Specht  committed 1a12bba Draft

load viewmodel by DI

  • Participants
  • Parent commits 3e6a8e7

Comments (0)

Files changed (2)

File src/MissileSharp.Launcher/App.xaml.cs

             var builder = new ContainerBuilder();
 
             builder.RegisterAssemblyTypes(typeof(App).Assembly)
+                .Where(t => t.Name.EndsWith("Window"))
+                .AsSelf();
+
+            builder.RegisterAssemblyTypes(typeof(App).Assembly)
                 .Where(t => t.Name.EndsWith("ViewModel"))
                 .AsSelf();
 
 
             var container = builder.Build();
 
-            var window = new MainWindow();
-            var viewmodel = container.Resolve<MainWindowViewModel>();
-            window.DataContext = viewmodel;
+            var window = container.Resolve<MainWindow>();
             window.Show();
         }
     }

File src/MissileSharp.Launcher/Views/MainWindow.xaml.cs

 using MahApps.Metro.Controls;
+using MissileSharp.Launcher.ViewModels;
 
 namespace MissileSharp.Launcher
 {
     /// </summary>
     public partial class MainWindow : MetroWindow
     {
-        public MainWindow()
+        public MainWindow(MainWindowViewModel viewmodel)
         {
+            this.DataContext = viewmodel;
             InitializeComponent();
         }
     }