This commit is contained in:
454313500@qq.com
2021-03-28 20:56:27 +08:00
parent 1bdeb1d6a4
commit b1549f00b6
3 changed files with 17 additions and 4 deletions

View File

@@ -22,10 +22,10 @@ namespace CC.Yi.API
{
logger.Debug("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Yi<59><69><EFBFBD><EFBFBD><EFBFBD>ܡ<EFBFBD><DCA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
var host = CreateHostBuilder(args).Build();
var scope = host.Services.CreateScope();
var services = scope.ServiceProvider;
var context = services.GetRequiredService<Model.DataContext>();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
//var scope = host.Services.CreateScope();
//var services = scope.ServiceProvider;
//var context = services.GetRequiredService<Model.DataContext>();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
//DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
host.Run();
logger.Info("Yi<59><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
}

View File

@@ -75,11 +75,21 @@ namespace CC.Yi.API
}).AddEntityFrameworkStores<DataContext>().AddDefaultTokenProviders();
}
private void InitData(IServiceProvider serviceProvider)
{
var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope();
var context = serviceScope.ServiceProvider.GetService<DataContext>();
DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
@@ -99,6 +109,7 @@ namespace CC.Yi.API
{
endpoints.MapControllers();
});
InitData(app.ApplicationServices);
}
}
}

View File

@@ -9,6 +9,8 @@ namespace CC.Yi.DAL
public class DbContentFactory
{
private static DataContext Webcontext;
public static void Initialize(DataContext webContext)
{
Webcontext = webContext;