mirror of https://github.com/abpframework/abp.git
1 changed files with 29 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.EntityFrameworkCore.Design; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace Volo.Abp.EntityFrameworkCore.Design; |
||||
|
|
||||
|
public abstract class AbpDesignTimeDbContextBase<TModule, TContext> : IDesignTimeDbContextFactory<TContext> |
||||
|
where TModule : AbpModule |
||||
|
where TContext : DbContext |
||||
|
{ |
||||
|
public virtual TContext CreateDbContext(string[] args) |
||||
|
{ |
||||
|
return AsyncHelper.RunSync(() => CreateDbContextAsync(args)); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<TContext> CreateDbContextAsync(string[] args) |
||||
|
{ |
||||
|
var application = await AbpApplicationFactory.CreateAsync<TModule>(); |
||||
|
application.Services.ReplaceConfiguration(BuildConfiguration()); |
||||
|
await application.InitializeAsync(); |
||||
|
return application.ServiceProvider.GetRequiredService<TContext>(); |
||||
|
} |
||||
|
|
||||
|
protected abstract IConfigurationRoot BuildConfiguration(); |
||||
|
} |
||||
Loading…
Reference in new issue