zhengyiming
2025-04-18 63eb46113cc6b57202ab68e5e84f947494121aef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using LifePayment.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System.IO;
using Volo.Abp.Identity.EntityFrameworkCore;
 
namespace LifePayment.Host
{
    public class DesignFactory : IDesignTimeDbContextFactory<LifePaymentServicesDbContext>
    {
        public LifePaymentServicesDbContext CreateDbContext(string[] args)
        {
            var configuration = BuildHelper.BuildConfiguration();
            var builder = new DbContextOptionsBuilder<LifePaymentServicesDbContext>()
                .UseSqlServer(configuration.GetConnectionString("LifePaymentServices"),
                b => b.MigrationsAssembly("LifePaymentService.Host"));
            return new LifePaymentServicesDbContext(builder.Options);
        }
    }
 
    public class IdentityDesignFactory : IDesignTimeDbContextFactory<IdentityDbContext>
    {
        public IdentityDbContext CreateDbContext(string[] args)
        {
            var configuration = BuildHelper.BuildConfiguration();
            var builder = new DbContextOptionsBuilder<IdentityDbContext>()
                .UseSqlServer(configuration.GetConnectionString("AbpIdentity"),
                b => b.MigrationsAssembly("LifePaymentService.Host"));
            return new IdentityDbContext(builder.Options);
        }
    }
 
    public class BuildHelper
    {
        public static IConfigurationRoot BuildConfiguration()
        {
            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: false);
            return builder.Build();
        }
    }
}