mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Create interface for providing store id to plugins (#3910)
This commit is contained in:
parent
ed1f249aaf
commit
b8f1c0df09
4 changed files with 33 additions and 0 deletions
7
BTCPayServer.Abstractions/Contracts/IScopeProvider.cs
Normal file
7
BTCPayServer.Abstractions/Contracts/IScopeProvider.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
#nullable enable
|
||||
namespace BTCPayServer.Abstractions.Contracts;
|
||||
|
||||
public interface IScopeProvider
|
||||
{
|
||||
string? GetCurrentStoreId();
|
||||
}
|
|
@ -22,6 +22,7 @@ using BTCPayServer.Models;
|
|||
using BTCPayServer.Models.StoreViewModels;
|
||||
using BTCPayServer.Payments;
|
||||
using BTCPayServer.Payments.Bitcoin;
|
||||
using BTCPayServer.Security;
|
||||
using BTCPayServer.Services.Invoices;
|
||||
using BTCPayServer.Services.Wallets;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
@ -257,6 +258,11 @@ namespace BTCPayServer
|
|||
}
|
||||
}
|
||||
|
||||
public static string GetCurrentStoreId(this HttpContext ctx)
|
||||
{
|
||||
return ctx.GetImplicitStoreId() ?? ctx.GetUserPrefsCookie()?.CurrentStoreId;
|
||||
}
|
||||
|
||||
public static StoreData GetStoreData(this HttpContext ctx)
|
||||
{
|
||||
return ctx.Items.TryGet("BTCPAY.STOREDATA") as StoreData;
|
||||
|
|
|
@ -98,6 +98,7 @@ namespace BTCPayServer.Hosting
|
|||
if (configuration.SupportChain("yec") || configuration.SupportChain("zec"))
|
||||
services.AddZcashLike();
|
||||
#endif
|
||||
services.AddScoped<IScopeProvider, ScopeProvider>();
|
||||
services.TryAddSingleton<SettingsRepository>();
|
||||
services.TryAddSingleton<ISettingsRepository>(provider => provider.GetService<SettingsRepository>());
|
||||
services.TryAddSingleton<IStoreRepository>(provider => provider.GetService<StoreRepository>());
|
||||
|
|
19
BTCPayServer/Services/Stores/ScopeProvider.cs
Normal file
19
BTCPayServer/Services/Stores/ScopeProvider.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
#nullable enable
|
||||
using BTCPayServer.Abstractions.Contracts;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace BTCPayServer.Services.Stores;
|
||||
|
||||
public class ScopeProvider : IScopeProvider
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public ScopeProvider(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
public string? GetCurrentStoreId()
|
||||
{
|
||||
return _httpContextAccessor.HttpContext.GetStoreData()?.Id;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue