34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using New_College.Common;
|
|
using New_College.Model.Seed;
|
|
using log4net;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using System;
|
|
|
|
namespace New_College.Extensions
|
|
{
|
|
/// <summary>
|
|
/// 生成种子数据中间件服务
|
|
/// </summary>
|
|
public static class SeedDataMildd
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(SeedDataMildd));
|
|
public static void UseSeedDataMildd(this IApplicationBuilder app, MyContext myContext, string webRootPath)
|
|
{
|
|
if (app == null) throw new ArgumentNullException(nameof(app));
|
|
|
|
try
|
|
{
|
|
if (Appsettings.app("AppSettings", "SeedDBEnabled").ObjToBool() || Appsettings.app("AppSettings", "SeedDBDataEnabled").ObjToBool())
|
|
{
|
|
DBSeed.SeedAsync(myContext, webRootPath).Wait();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error($"Error occured seeding the Database.\n{e.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|