mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 05:54:26 +01:00
Merge pull request #6988 from NicolasDorier/ui-extension-registry
Refactor: Add UIExtensionsRegistry
This commit is contained in:
@@ -2,27 +2,18 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BTCPayServer.Abstractions.Contracts;
|
using BTCPayServer.Abstractions.Contracts;
|
||||||
|
using BTCPayServer.Services;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace BTCPayServer.Components.UIExtensionPoint
|
namespace BTCPayServer.Components.UIExtensionPoint
|
||||||
{
|
{
|
||||||
public class UiExtensionPoint : ViewComponent
|
public class UiExtensionPoint(UIExtensionsRegistry uiExtensions) : ViewComponent
|
||||||
{
|
{
|
||||||
private readonly IEnumerable<IUIExtension> _uiExtensions;
|
|
||||||
|
|
||||||
public UiExtensionPoint(IEnumerable<IUIExtension> uiExtensions)
|
|
||||||
{
|
|
||||||
_uiExtensions = uiExtensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IViewComponentResult Invoke(string location, object model)
|
public IViewComponentResult Invoke(string location, object model)
|
||||||
{
|
{
|
||||||
return View(new UiExtensionPointViewModel()
|
return View(new UiExtensionPointViewModel()
|
||||||
{
|
{
|
||||||
Partials = _uiExtensions
|
Partials = uiExtensions.ExtensionsByLocation[location].Select(c => c.Partial).ToArray(),
|
||||||
.Where(extension =>
|
|
||||||
extension.Location.Equals(location, StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
.Select(extension => extension.Partial).ToArray(),
|
|
||||||
Model = model
|
Model = model
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ namespace BTCPayServer.Hosting
|
|||||||
services.TryAddSingleton<ViewLocalizer>();
|
services.TryAddSingleton<ViewLocalizer>();
|
||||||
services.TryAddSingleton<IStringLocalizer>(o => o.GetRequiredService<IStringLocalizerFactory>().Create("",""));
|
services.TryAddSingleton<IStringLocalizer>(o => o.GetRequiredService<IStringLocalizerFactory>().Create("",""));
|
||||||
services.TryAddSingleton<DelayedTaskScheduler>();
|
services.TryAddSingleton<DelayedTaskScheduler>();
|
||||||
|
services.TryAddSingleton<UIExtensionsRegistry>();
|
||||||
|
|
||||||
services.AddSingleton<MvcNewtonsoftJsonOptions>(o => o.GetRequiredService<IOptions<MvcNewtonsoftJsonOptions>>().Value);
|
services.AddSingleton<MvcNewtonsoftJsonOptions>(o => o.GetRequiredService<IOptions<MvcNewtonsoftJsonOptions>>().Value);
|
||||||
services.AddSingleton<JsonSerializerSettings>(o => o.GetRequiredService<IOptions<MvcNewtonsoftJsonOptions>>().Value.SerializerSettings);
|
services.AddSingleton<JsonSerializerSettings>(o => o.GetRequiredService<IOptions<MvcNewtonsoftJsonOptions>>().Value.SerializerSettings);
|
||||||
|
|||||||
17
BTCPayServer/Services/UIExtensionsRegistry.cs
Normal file
17
BTCPayServer/Services/UIExtensionsRegistry.cs
Normal file
@@ -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<IUIExtension> uiExtensions)
|
||||||
|
{
|
||||||
|
ExtensionsByLocation = uiExtensions.OfType<UIExtension>().ToLookup(o => o.Location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ILookup<string, UIExtension> ExtensionsByLocation { get; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user