btcpayserver/BTCPayServer.Plugins.Test/Services/TestPluginService.cs
Kukks 179520a211 Plugins: Allow creation of independent DbContexts
This allows plugins to create custom dbcontexts, which would be namespaced in the scheme with a prefix. Migrations are supported too and the table would be prefixed too
2020-11-18 12:27:26 +01:00

33 lines
1,015 B
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using BTCPayServer.Plugins.Test.Data;
using Microsoft.EntityFrameworkCore;
namespace BTCPayServer.Plugins.Test.Services
{
public class TestPluginService
{
private readonly TestPluginDbContextFactory _testPluginDbContextFactory;
public TestPluginService(TestPluginDbContextFactory testPluginDbContextFactory)
{
_testPluginDbContextFactory = testPluginDbContextFactory;
}
public async Task AddTestDataRecord()
{
await using var context = _testPluginDbContextFactory.CreateContext();
await context.TestPluginRecords.AddAsync(new TestPluginData() {Timestamp = DateTimeOffset.UtcNow});
}
public async Task<List<TestPluginData>> Get()
{
await using var context = _testPluginDbContextFactory.CreateContext();
return await context.TestPluginRecords.ToListAsync();
}
}
}