105 lines
3.6 KiB
C#
105 lines
3.6 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 Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace Dlhis.Entity;
|
|
|
|
public class SqlSugarPack : BaseAppPack
|
|
{
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddSqlSugar(DbType.MySqlConnector, sp =>
|
|
{
|
|
var configuration = sp.GetService<IConfiguration>();
|
|
|
|
return new List<ConnectionConfig>
|
|
{
|
|
new()
|
|
{
|
|
ConfigId = "default",
|
|
|
|
ConnectionString = configuration.GetSection("SqlSugarOptions:DefaultConnectionString").Value,
|
|
DbType = DbType.MySqlConnector,
|
|
InitKeyType = InitKeyType.Attribute,
|
|
IsAutoCloseConnection = true,
|
|
|
|
MoreSettings = new ConnMoreSettings
|
|
{
|
|
DisableNvarchar = true,
|
|
}
|
|
},
|
|
new()
|
|
{
|
|
ConfigId = "identity",
|
|
|
|
ConnectionString = configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value,
|
|
DbType = DbType.MySqlConnector,
|
|
InitKeyType = InitKeyType.Attribute,
|
|
IsAutoCloseConnection = true,
|
|
|
|
MoreSettings = new ConnMoreSettings
|
|
{
|
|
DisableNvarchar = true,
|
|
}
|
|
},
|
|
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)
|
|
{
|
|
return;
|
|
}
|
|
|
|
using var scope = app.ApplicationServices.CreateScope();
|
|
var db = scope.ServiceProvider.GetService<IDbContext>();
|
|
var tables = App.ActiveTypes.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>();
|
|
}
|
|
} |