diff --git a/BTCPayServer.Tests/CrowdfundTests.cs b/BTCPayServer.Tests/CrowdfundTests.cs index 23449ff89..3cd78f402 100644 --- a/BTCPayServer.Tests/CrowdfundTests.cs +++ b/BTCPayServer.Tests/CrowdfundTests.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Controllers; +using BTCPayServer.Crowdfund; using BTCPayServer.Data; using BTCPayServer.Events; using BTCPayServer.Hubs; diff --git a/BTCPayServer/Controllers/AppsPublicController.cs b/BTCPayServer/Controllers/AppsPublicController.cs index 4d97d60fe..e2543037a 100644 --- a/BTCPayServer/Controllers/AppsPublicController.cs +++ b/BTCPayServer/Controllers/AppsPublicController.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; +using BTCPayServer.Crowdfund; using BTCPayServer.Data; using BTCPayServer.Filters; using BTCPayServer.Hubs; diff --git a/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs b/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs index 7e1f69105..c1bf80c99 100644 --- a/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs +++ b/BTCPayServer/Crowdfund/CrowdfundHubStreamer.cs @@ -2,11 +2,11 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using System.Threading; using System.Threading.Tasks; using BTCPayServer.Controllers; using BTCPayServer.Data; using BTCPayServer.Events; +using BTCPayServer.Hubs; using BTCPayServer.Models.AppViewModels; using BTCPayServer.Payments; using BTCPayServer.Rating; @@ -16,14 +16,11 @@ using BTCPayServer.Services.Rates; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Primitives; using NBitcoin; -using YamlDotNet.Core; -namespace BTCPayServer.Hubs +namespace BTCPayServer.Crowdfund { - public class - CrowdfundHubStreamer + public class CrowdfundHubStreamer: IDisposable { public const string CrowdfundInvoiceOrderIdPrefix = "crowdfund-app_"; private readonly EventAggregator _EventAggregator; @@ -37,7 +34,9 @@ namespace BTCPayServer.Hubs private readonly ConcurrentDictionary _QuickAppInvoiceLookup = new ConcurrentDictionary(); - + + private List _Subscriptions; + public CrowdfundHubStreamer(EventAggregator eventAggregator, IHubContext hubContext, IMemoryCache memoryCache, @@ -116,13 +115,15 @@ namespace BTCPayServer.Hubs private void SubscribeToEvents() { - - _EventAggregator.Subscribe(OnInvoiceEvent); - _EventAggregator.Subscribe(updated => + _Subscriptions = new List() { - UpdateLookup(updated.AppId, updated.StoreId, updated.Settings); - InvalidateCacheForApp(updated.AppId); - }); + _EventAggregator.Subscribe(OnInvoiceEvent), + _EventAggregator.Subscribe(updated => + { + UpdateLookup(updated.AppId, updated.StoreId, updated.Settings); + InvalidateCacheForApp(updated.AppId); + }) + }; } private string GetCacheKey(string appId) @@ -361,5 +362,10 @@ namespace BTCPayServer.Hubs StartDate = startDate }); } + + public void Dispose() + { + _Subscriptions.ForEach(subscription => subscription.Dispose()); + } } } diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs index e2f05e477..518e9c96a 100644 --- a/BTCPayServer/Hosting/BTCPayServerServices.cs +++ b/BTCPayServer/Hosting/BTCPayServerServices.cs @@ -38,6 +38,7 @@ using BTCPayServer.Logging; using BTCPayServer.HostedServices; using Meziantou.AspNetCore.BundleTagHelpers; using System.Security.Claims; +using BTCPayServer.Crowdfund; using BTCPayServer.Hubs; using BTCPayServer.Payments.Changelly; using BTCPayServer.Payments.Lightning; diff --git a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml index 895ec8f3d..1af73a633 100644 --- a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml @@ -1,4 +1,5 @@ -@using BTCPayServer.Hubs +@using BTCPayServer.Crowdfund +@using BTCPayServer.Hubs @addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers @model UpdateCrowdfundViewModel @{