You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
using Ds.Module.AppStartup;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar.IOC;
|
|
|
|
namespace DS.Module.SqlSugar
|
|
{
|
|
[DsStartup(7)]
|
|
public class SqlSugarAppStartup : IDynamicStartup
|
|
{
|
|
public void Configure(WebApplication app)
|
|
{
|
|
}
|
|
|
|
public void ConfigureServices(WebApplicationBuilder builder)
|
|
{
|
|
SugarIocServices.AddSqlSugar(new IocConfig()
|
|
{
|
|
ConfigId = 200,// 多租户用到
|
|
ConnectionString = "server=60.209.125.238;port=32006;uid=root;pwd=Djy@Mysql.test;database=shippingweb8_log",
|
|
DbType = IocDbType.MySql,
|
|
IsAutoCloseConnection = true//自动释放
|
|
}); //多
|
|
|
|
SugarIocServices.ConfigurationSugar(db =>
|
|
{
|
|
db.Aop.OnLogExecuting = (sql, p) =>
|
|
{
|
|
Console.WriteLine(sql);
|
|
};
|
|
//设置更多连接参数
|
|
//db.CurrentConnectionConfig.XXXX=XXXX
|
|
//db.CurrentConnectionConfig.MoreSettings=new ConnMoreSettings(){}
|
|
//二级缓存设置
|
|
//db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices()
|
|
//{
|
|
// DataInfoCacheService = myCache //配置我们创建的缓存类
|
|
//}
|
|
//读写分离设置
|
|
//laveConnectionConfigs = new List<SlaveConnectionConfig>(){...}
|
|
|
|
/*多租户注意*/
|
|
//单库是db.CurrentConnectionConfig
|
|
//多租户需要db.GetConnection(configId).CurrentConnectionConfig
|
|
//db.GetConnection(200).CodeFirst.SetStringDefaultLength(500).InitTables(typeof(Sys_Log_DataAop));
|
|
});
|
|
//数据操作仓储
|
|
builder.Services.AddScoped(typeof(DsDataAppService<>));
|
|
|
|
//sqlsugar注册
|
|
builder.Services.AddSqlSugarInstall();
|
|
}
|
|
}
|
|
} |