From 65744e77d95a39ba5a0c7ea8e8f2eb05abeab1dd Mon Sep 17 00:00:00 2001 From: Kasper Marstal Date: Tue, 24 Sep 2024 21:15:12 +0200 Subject: [PATCH] feat: Manually dispose of ServiceLocator (#7) --- src/Cellm/AddIn/Cellm.cs | 4 +++- src/Cellm/Services/ServiceLocator.cs | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Cellm/AddIn/Cellm.cs b/src/Cellm/AddIn/Cellm.cs index cc03694..42ffc2b 100644 --- a/src/Cellm/AddIn/Cellm.cs +++ b/src/Cellm/AddIn/Cellm.cs @@ -1,4 +1,5 @@ -using ExcelDna.Integration; +using Cellm.Services; +using ExcelDna.Integration; namespace Cellm.AddIn; @@ -16,6 +17,7 @@ public void AutoOpen() public void AutoClose() { + ServiceLocator.Dispose(); SentrySdk.Flush(); } } diff --git a/src/Cellm/Services/ServiceLocator.cs b/src/Cellm/Services/ServiceLocator.cs index 6eb6127..ec70586 100644 --- a/src/Cellm/Services/ServiceLocator.cs +++ b/src/Cellm/Services/ServiceLocator.cs @@ -132,4 +132,12 @@ private static IServiceCollection ConfigureServices(IServiceCollection services) return services; } + + public static void Dispose() + { + if (_serviceProvider.IsValueCreated) + { + (_serviceProvider.Value as IDisposable)?.Dispose(); + } + } }