From 1dbb2b6abe55f32534be911803d97984ff5e16e5 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 18 Sep 2024 15:03:56 +0100 Subject: [PATCH] Dispose Containers (except for Autocad) (#250) --- .../Speckle.Connectors.ArcGIS3/SpeckleModule.cs | 1 + .../Plugin/RevitExternalApplication.cs | 1 + .../Plugin/Speckle.Connectors.RhinoPlugin.cs | 1 + .../DUI3ControlWebView.xaml.cs | 5 ++++- .../DependencyInjection/SpeckleContainer.cs | 16 ++++------------ 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/SpeckleModule.cs b/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/SpeckleModule.cs index f857ebd52..88a2d1399 100644 --- a/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/SpeckleModule.cs +++ b/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/SpeckleModule.cs @@ -60,6 +60,7 @@ protected override bool CanUnload() //TODO - add your business logic //return false to ~cancel~ Application close _disposableLogger?.Dispose(); + Container.Dispose(); return true; } } diff --git a/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs b/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs index 2b29e0a68..46bc1a248 100644 --- a/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs +++ b/Connectors/Revit/Speckle.Connectors.RevitShared/Plugin/RevitExternalApplication.cs @@ -74,6 +74,7 @@ public Result OnShutdown(UIControlledApplication application) // need to look for commonality _revitPlugin?.Shutdown(); _disposableLogger?.Dispose(); + _container?.Dispose(); } catch (Exception e) when (!e.IsFatal()) { diff --git a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Plugin/Speckle.Connectors.RhinoPlugin.cs b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Plugin/Speckle.Connectors.RhinoPlugin.cs index e2dc70b16..e1fe808d3 100644 --- a/Connectors/Rhino/Speckle.Connectors.RhinoShared/Plugin/Speckle.Connectors.RhinoPlugin.cs +++ b/Connectors/Rhino/Speckle.Connectors.RhinoShared/Plugin/Speckle.Connectors.RhinoPlugin.cs @@ -87,6 +87,7 @@ protected override void OnShutdown() { _rhinoPlugin?.Shutdown(); _disposableLogger?.Dispose(); + Container?.Dispose(); base.OnShutdown(); } } diff --git a/DUI3/Speckle.Connectors.DUI.WebView/DUI3ControlWebView.xaml.cs b/DUI3/Speckle.Connectors.DUI.WebView/DUI3ControlWebView.xaml.cs index 45ed0bf6a..8f7ed9b94 100644 --- a/DUI3/Speckle.Connectors.DUI.WebView/DUI3ControlWebView.xaml.cs +++ b/DUI3/Speckle.Connectors.DUI.WebView/DUI3ControlWebView.xaml.cs @@ -6,7 +6,7 @@ namespace Speckle.Connectors.DUI.WebView; -public sealed partial class DUI3ControlWebView : UserControl, IBrowserScriptExecutor +public sealed partial class DUI3ControlWebView : UserControl, IBrowserScriptExecutor, IDisposable { private readonly IEnumerable> _bindings; @@ -58,4 +58,7 @@ private void SetupBinding(IBinding binding) } public void ShowDevTools() => Browser.CoreWebView2.OpenDevToolsWindow(); + + //https://github.com/MicrosoftEdge/WebView2Feedback/issues/2161 + public void Dispose() => Browser.Dispatcher.Invoke(() => Browser.Dispose(), DispatcherPriority.Send); } diff --git a/Sdk/Speckle.Autofac/DependencyInjection/SpeckleContainer.cs b/Sdk/Speckle.Autofac/DependencyInjection/SpeckleContainer.cs index 189481d64..98dcab510 100644 --- a/Sdk/Speckle.Autofac/DependencyInjection/SpeckleContainer.cs +++ b/Sdk/Speckle.Autofac/DependencyInjection/SpeckleContainer.cs @@ -2,18 +2,10 @@ namespace Speckle.Autofac.DependencyInjection; -public class SpeckleContainer +public sealed class SpeckleContainer(IContainer container) : IDisposable { - private readonly IContainer _container; - - public SpeckleContainer(IContainer container) - { - _container = container; - } - public T Resolve() - where T : class - { - return _container.Resolve(); - } + where T : class => container.Resolve(); + + public void Dispose() => container.Dispose(); }