73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
using Dlhis.Entity.Basic.Entity;
|
|
using Kurisu.AspNetCore;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
using Kurisu.AspNetCore.Startup;
|
|
using SqlSugar;
|
|
|
|
namespace Dlhis.Basic.Packs;
|
|
|
|
public class SqlSugarPack : BaseAppPack
|
|
{
|
|
public override bool IsBeforeUseRouting { get; }
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddSqlSugar(sp =>
|
|
{
|
|
var configuration = sp.GetService<IConfiguration>();
|
|
|
|
return new List<ConnectionConfig>
|
|
{
|
|
new()
|
|
{
|
|
ConfigId = "face",
|
|
|
|
ConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value,
|
|
DbType = DbType.MySqlConnector,
|
|
InitKeyType = InitKeyType.Attribute,
|
|
IsAutoCloseConnection = true,
|
|
|
|
MoreSettings = new ConnMoreSettings
|
|
{
|
|
DisableNvarchar = true,
|
|
}
|
|
},
|
|
new()
|
|
{
|
|
ConfigId = "log",
|
|
|
|
ConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value,
|
|
DbType = DbType.MySqlConnector,
|
|
InitKeyType = InitKeyType.Attribute,
|
|
IsAutoCloseConnection = true,
|
|
|
|
MoreSettings = new ConnMoreSettings
|
|
{
|
|
DisableNvarchar = true,
|
|
}
|
|
},
|
|
};
|
|
});
|
|
}
|
|
|
|
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
var isGenerate = Configuration.GetSection("SqlSugarOptions").GetValue<bool>("Generate");
|
|
if (isGenerate)
|
|
{
|
|
using var scope = app.ApplicationServices.CreateScope();
|
|
var db = scope.ServiceProvider.GetService<IDbContext>();
|
|
// var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false))
|
|
// .Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
|
|
// .ToArray();
|
|
//
|
|
// db.Client.DbMaintenance.CreateDatabase();
|
|
// db.Client.CodeFirst.InitTables(tables);
|
|
//
|
|
// var faceDb = db.ChangeDb("face");
|
|
// faceDb.Client.DbMaintenance.CreateDatabase();
|
|
// faceDb.Client.CodeFirst.InitTables<GainfoFaceEntity>();
|
|
}
|
|
}
|
|
} |