mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 13:26:47 +01:00
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System;
|
|
using BTCPayServer.Abstractions.Contracts;
|
|
using BTCPayServer.Abstractions.Models;
|
|
using Laraue.EfCoreTriggers.PostgreSql.Extensions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
|
|
|
|
namespace BTCPayServer.Data
|
|
{
|
|
public class ApplicationDbContextFactory : BaseDbContextFactory<ApplicationDbContext>
|
|
{
|
|
public ApplicationDbContextFactory(IOptions<DatabaseOptions> options, ILoggerFactory loggerFactory) : base(options, "")
|
|
{
|
|
LoggerFactory = loggerFactory;
|
|
}
|
|
|
|
public ILoggerFactory LoggerFactory { get; }
|
|
|
|
public override ApplicationDbContext CreateContext(Action<NpgsqlDbContextOptionsBuilder> npgsqlOptionsAction = null)
|
|
{
|
|
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
|
builder.UseLoggerFactory(LoggerFactory);
|
|
builder.AddInterceptors(MigrationInterceptor.Instance);
|
|
ConfigureBuilder(builder, npgsqlOptionsAction);
|
|
|
|
builder.UsePostgreSqlTriggers();
|
|
return new ApplicationDbContext(builder.Options);
|
|
}
|
|
|
|
|
|
}
|
|
}
|