Files
number_zj/20220330_Vote/Ewide.EntityFramework.Core/Startup.cs
2022-03-30 19:34:37 +08:00

75 lines
3.3 KiB
C#

using Dapper;
using Ewide.EntityFramework.Core.SqlSugar;
using Furion;
using Furion.DatabaseAccessor;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Ewide.EntityFramework.Core
{
public class Startup : AppStartup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddDatabaseAccessor(options =>
{
options.CustomizeMultiTenants(); // 自定义租户
options.AddDb<DefaultDbContext>();
//options.AddDb<MultiTenantDbContext, MultiTenantDbContextLocator>();
}, "Ewide.Database.Migrations");
// 注册dapper, 目前只能强行写死连接字符串和数据库程序集
services.AddDapper(App.Configuration["DefaultConnection"], SqlProvider.MySql);
//sqlsugar的注册代码放到了SqlSugar文件夹里
services.AddSqlsugarSetup();
//List<ConnectionConfig> connectConfigList = new()
//{
// new ConnectionConfig
// {
// ConnectionString = App.Configuration["SqlServerConnectionString:DefaultConnection"],
// DbType = DbType.SqlServer,
// IsAutoCloseConnection = true,
// InitKeyType = InitKeyType.Attribute,
// ConfigId = "0",
// AopEvents = new AopEvents
// {
// OnLogExecuting = (sql, pars) =>
// {
// Debugger.Log(1, "", "=============================== SqlSugar log started ===============================\r\n");
// Debugger.Log(2, "语句:", sql);
// Debugger.Log(3, "参数:", string.Join(",", pars?.Select(it => it.ParameterName + ":" + it.Value)));
// Debugger.Log(4, "", "=============================== SqlSugar log end ===============================\r\n");
// }
// }
// },
// new ConnectionConfig
// {
// ConnectionString = App.Configuration["ConnectionStrings:RoadflowConnection"],
// DbType = DbType.MySql,
// IsAutoCloseConnection = true,
// InitKeyType = InitKeyType.Attribute,
// ConfigId = "RoadFlowDB",
// AopEvents = new AopEvents
// {
// OnLogExecuting = (sql, pars) =>
// {
// Debugger.Log(1, "", "=============================== Roadflow SqlSugar log started ===============================\r\n");
// Debugger.Log(2, "语句:", sql);
// Debugger.Log(3, "参数:", string.Join(",", pars?.Select(it => it.ParameterName + ":" + it.Value)));
// Debugger.Log(4, "", "=============================== SqlSugar log end ===============================\r\n");
// },
// }
// }
//};
//services.AddSqlSugar(connectConfigList.ToArray());
}
}
}