Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(bar): create new DI scope for each bar window launched

Lars Berger00fcd7b06c6c
diff --git a/GlazeWM.Bar/BarManagerService.cs b/GlazeWM.Bar/BarManagerService.cs
index 193c416f..e7ff226f 100644
--- a/GlazeWM.Bar/BarManagerService.cs
+++ b/GlazeWM.Bar/BarManagerService.cs
@@ -5,6 +5,8 @@ using System.Reactive.Linq;
using System;
using System.Threading;
using GlazeWM.Domain.UserConfigs;
+using GlazeWM.Infrastructure;
+using Microsoft.Extensions.DependencyInjection;
namespace GlazeWM.Bar
{
@@ -33,8 +35,17 @@ namespace GlazeWM.Bar
{
application.Dispatcher.Invoke(() =>
{
- var bar = new MainWindow((@event as MonitorAddedEvent).AddedMonitor, _workspaceService, _bus, _userConfigService);
- bar.Show();
+ using (var scope = ServiceLocator.Provider.CreateScope())
+ {
+ var barViewModel = scope.ServiceProvider.GetRequiredService<BarViewModel>();
+ barViewModel.Monitor = (@event as MonitorAddedEvent).AddedMonitor;
+ barViewModel.Dispatcher = application.Dispatcher;
+ barViewModel.InitializeState();
+
+ var barWindow = scope.ServiceProvider.GetRequiredService<MainWindow>();
+ barWindow.DataContext = barViewModel;
+ barWindow.Show();
+ }
});
});