diff --git a/BTCPayServer/Components/UiExtensionPoint/UIExtensionPoint.cs b/BTCPayServer/Components/UiExtensionPoint/UIExtensionPoint.cs index 7925758c5..e75b7fccc 100644 --- a/BTCPayServer/Components/UiExtensionPoint/UIExtensionPoint.cs +++ b/BTCPayServer/Components/UiExtensionPoint/UIExtensionPoint.cs @@ -2,27 +2,18 @@ using System; using System.Collections.Generic; using System.Linq; using BTCPayServer.Abstractions.Contracts; +using BTCPayServer.Services; using Microsoft.AspNetCore.Mvc; namespace BTCPayServer.Components.UIExtensionPoint { - public class UiExtensionPoint : ViewComponent + public class UiExtensionPoint(UIExtensionsRegistry uiExtensions) : ViewComponent { - private readonly IEnumerable _uiExtensions; - - public UiExtensionPoint(IEnumerable uiExtensions) - { - _uiExtensions = uiExtensions; - } - public IViewComponentResult Invoke(string location, object model) { return View(new UiExtensionPointViewModel() { - Partials = _uiExtensions - .Where(extension => - extension.Location.Equals(location, StringComparison.InvariantCultureIgnoreCase)) - .Select(extension => extension.Partial).ToArray(), + Partials = uiExtensions.ExtensionsByLocation[location].Select(c => c.Partial).ToArray(), Model = model }); } diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs index 2eefa55a1..67853e5c3 100644 --- a/BTCPayServer/Hosting/BTCPayServerServices.cs +++ b/BTCPayServer/Hosting/BTCPayServerServices.cs @@ -94,6 +94,7 @@ namespace BTCPayServer.Hosting services.TryAddSingleton(); services.TryAddSingleton(o => o.GetRequiredService().Create("","")); services.TryAddSingleton(); + services.TryAddSingleton(); services.AddSingleton(o => o.GetRequiredService>().Value); services.AddSingleton(o => o.GetRequiredService>().Value.SerializerSettings); diff --git a/BTCPayServer/Services/UIExtensionsRegistry.cs b/BTCPayServer/Services/UIExtensionsRegistry.cs new file mode 100644 index 000000000..b91dfee71 --- /dev/null +++ b/BTCPayServer/Services/UIExtensionsRegistry.cs @@ -0,0 +1,17 @@ +#nullable enable +using System.Collections.Generic; +using System.Linq; +using BTCPayServer.Abstractions.Contracts; +using BTCPayServer.Abstractions.Services; + +namespace BTCPayServer.Services; + +public class UIExtensionsRegistry +{ + public UIExtensionsRegistry(IEnumerable uiExtensions) + { + ExtensionsByLocation = uiExtensions.OfType().ToLookup(o => o.Location); + } + + public ILookup ExtensionsByLocation { get; } +}