Refactor: Remove uneeded dependencies to PaymentMethodHandlerDictionary

This commit is contained in:
nicolas.dorier
2019-06-04 10:17:26 +09:00
parent 01787e2662
commit bea08e5cfd
6 changed files with 9 additions and 34 deletions

View File

@@ -28,9 +28,6 @@ namespace BTCPayServer.Data
{
public class StoreData
{
[NotMapped]
[JsonIgnore]
public PaymentMethodHandlerDictionary PaymentMethodHandlerDictionary { get; set; }
public string Id
{
get;

View File

@@ -93,7 +93,6 @@ namespace BTCPayServer.HostedServices
foreach (var store in await ctx.Stores.ToArrayAsync())
{
#pragma warning disable CS0618 // Type or member is obsolete
_StoreRepository.PrepareEntity(store);
var blob = store.GetStoreBlob();
if (blob.WalletKeyPathRoots == null)
continue;
@@ -139,7 +138,6 @@ namespace BTCPayServer.HostedServices
{
foreach (var store in await ctx.Stores.ToArrayAsync())
{
_StoreRepository.PrepareEntity(store);
var blob = store.GetStoreBlob();
#pragma warning disable CS0618 // Type or member is obsolete
if (blob.NetworkFeeDisabled != null)
@@ -160,7 +158,6 @@ namespace BTCPayServer.HostedServices
{
foreach (var store in await ctx.Stores.ToArrayAsync())
{
_StoreRepository.PrepareEntity(store);
var blob = store.GetStoreBlob();
#pragma warning disable CS0612 // Type or member is obsolete
decimal multiplier = 1.0m;
@@ -191,7 +188,6 @@ namespace BTCPayServer.HostedServices
{
foreach (var store in await ctx.Stores.ToArrayAsync())
{
_StoreRepository.PrepareEntity(store);
foreach (var method in store.GetSupportedPaymentMethods(_NetworkProvider).OfType<Payments.Lightning.LightningSupportedPaymentMethod>())
{
var lightning = method.GetLightningUrl();

View File

@@ -71,12 +71,10 @@ namespace BTCPayServer.Hosting
{
var opts = o.GetRequiredService<BTCPayServerOptions>();
var dbContext = o.GetRequiredService<ApplicationDbContextFactory>();
var paymentMethodHandlerDictionary = o.GetService<PaymentMethodHandlerDictionary>();
var dbpath = Path.Combine(opts.DataDir, "InvoiceDB");
if (!Directory.Exists(dbpath))
Directory.CreateDirectory(dbpath);
return new InvoiceRepository(dbContext, dbpath, o.GetRequiredService<BTCPayNetworkProvider>(),
paymentMethodHandlerDictionary);
return new InvoiceRepository(dbContext, dbpath, o.GetRequiredService<BTCPayNetworkProvider>());
});
services.AddSingleton<BTCPayServerEnvironment>();
services.TryAddSingleton<TokenRepository>();

View File

@@ -38,11 +38,10 @@ namespace BTCPayServer.Services.Invoices
private ApplicationDbContextFactory _ContextFactory;
private readonly BTCPayNetworkProvider _Networks;
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
private CustomThreadPool _IndexerThread;
public InvoiceRepository(ApplicationDbContextFactory contextFactory, string dbreezePath,
BTCPayNetworkProvider networks, PaymentMethodHandlerDictionary paymentMethodHandlerDictionary)
BTCPayNetworkProvider networks)
{
int retryCount = 0;
retry:
@@ -53,8 +52,7 @@ retry:
catch when (retryCount++ < 5) { goto retry; }
_IndexerThread = new CustomThreadPool(1, "Invoice Indexer");
_ContextFactory = contextFactory;
_Networks = networks;
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
_Networks = networks.UnfilteredNetworks;
}
public InvoiceEntity CreateNewInvoice()
@@ -715,7 +713,7 @@ retry:
private InvoiceEntity ToObject(byte[] value)
{
var entity = NBitcoin.JsonConverters.Serializer.ToObject<InvoiceEntity>(ZipUtils.Unzip(value), null);
entity.Networks = _Networks?.UnfilteredNetworks;
entity.Networks = _Networks;
return entity;
}
private T ToObject<T>(byte[] value, BTCPayNetworkBase network)

View File

@@ -61,11 +61,6 @@ namespace BTCPayServer.Services.PaymentRequests
string.IsNullOrEmpty(userId) ||
(data.StoreData != null && data.StoreData.UserStores.Any(u => u.ApplicationUserId == userId)))
.SingleOrDefaultAsync(x => x.Id == id, cancellationToken);
if (result != null)
{
result.StoreData = _storeRepository.PrepareEntity(result.StoreData);
}
return result;
}
}

View File

@@ -14,12 +14,10 @@ namespace BTCPayServer.Services.Stores
public class StoreRepository
{
private ApplicationDbContextFactory _ContextFactory;
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
public StoreRepository(ApplicationDbContextFactory contextFactory, PaymentMethodHandlerDictionary paymentMethodHandlerDictionary)
public StoreRepository(ApplicationDbContextFactory contextFactory)
{
_ContextFactory = contextFactory ?? throw new ArgumentNullException(nameof(contextFactory));
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
}
public async Task<StoreData> FindStore(string storeId)
@@ -29,7 +27,7 @@ namespace BTCPayServer.Services.Stores
using (var ctx = _ContextFactory.CreateContext())
{
var result = await ctx.FindAsync<StoreData>(storeId).ConfigureAwait(false);
return PrepareEntity(result);
return result;
}
}
@@ -52,7 +50,7 @@ namespace BTCPayServer.Services.Stores
#pragma warning disable CS0612 // Type or member is obsolete
us.Store.Role = us.Role;
#pragma warning restore CS0612 // Type or member is obsolete
return PrepareEntity(us.Store);
return us.Store;
}).FirstOrDefault();
}
}
@@ -94,7 +92,7 @@ namespace BTCPayServer.Services.Stores
#pragma warning disable CS0612 // Type or member is obsolete
u.StoreData.Role = u.Role;
#pragma warning restore CS0612 // Type or member is obsolete
return PrepareEntity(u.StoreData);
return u.StoreData;
}).ToArray();
}
}
@@ -186,7 +184,7 @@ namespace BTCPayServer.Services.Stores
ctx.Add(store);
ctx.Add(userStore);
await ctx.SaveChangesAsync().ConfigureAwait(false);
return PrepareEntity(store);
return store;
}
}
@@ -235,12 +233,5 @@ namespace BTCPayServer.Services.Stores
return ctx.Database.SupportDropForeignKey();
}
}
public StoreData PrepareEntity(StoreData storeData)
{
if(storeData != null)
storeData.PaymentMethodHandlerDictionary = _paymentMethodHandlerDictionary;
return storeData;
}
}
}