优化sqlsugar启动

This commit is contained in:
yubaolee 2023-09-02 11:40:07 +08:00
parent 16421f9a8b
commit 115c79bd9c
2 changed files with 20 additions and 98 deletions

View File

@ -94,47 +94,18 @@ namespace OpenAuth.IdentityServer
options.UseOracle(connectionString, o=>o.UseOracleSQLCompatibility("11")));
}
services.AddScoped<ISqlSugarClient>(s =>
{
var sqlsugarTypes = UtilMethods.EnumToDictionary<SqlSugar.DbType>();
var sugarDbtype = sqlsugarTypes.FirstOrDefault(it =>
dbtypes.ToDictionary(u => u.Key, v => v.Value.ToLower()).ContainsValue(it.Key));
SqlSugarClient sqlSugar;
if(dbtypes.ContainsValue(Define.DBTYPE_SQLSERVER))
services.AddScoped<ISqlSugarClient>(s =>
{
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
{
sqlSugar = new SqlSugarClient (new ConnectionConfig()
{
DbType = SqlSugar.DbType.SqlServer,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
});
}
else if(dbtypes.ContainsValue(Define.DBTYPE_MYSQL)) //mysql
{
sqlSugar = new SqlSugarClient (new ConnectionConfig()
{
DbType = SqlSugar.DbType.MySql,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
});
}
else if(dbtypes.ContainsValue(Define.DBTYPE_PostgreSQL)) //PostgreSQL
{
sqlSugar = new SqlSugarClient (new ConnectionConfig()
{
DbType = SqlSugar.DbType.PostgreSQL,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
});
}
else
{
sqlSugar = new SqlSugarClient (new ConnectionConfig()
{
DbType = SqlSugar.DbType.Oracle,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
});
}
DbType = sugarDbtype.Value,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
});
return sqlSugar;
});

View File

@ -101,67 +101,18 @@ namespace OpenAuth.Mvc
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Configuration["DataProtection"]));
services.AddScoped<ISqlSugarClient>(s =>
{
var sqlsugarTypes = UtilMethods.EnumToDictionary<SqlSugar.DbType>();
var dbType = sqlsugarTypes.FirstOrDefault(it =>
dbtypes.ToDictionary(u => u.Key, v => v.Value.ToLower()).ContainsValue(it.Key));
SqlSugarClient sqlSugar;
if(dbtypes.ContainsValue(Define.DBTYPE_SQLSERVER))
services.AddScoped<ISqlSugarClient>(s =>
{
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
{
sqlSugar = new SqlSugarClient (new ConnectionConfig()
{
DbType = SqlSugar.DbType.SqlServer,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
},db=>{
db.Aop.OnLogExecuting = (sql, pars) =>
{
logger.LogInformation(sql);
};
});
}
else if(dbtypes.ContainsValue(Define.DBTYPE_MYSQL)) //mysql
{
sqlSugar = new SqlSugarClient (new ConnectionConfig()
{
DbType = SqlSugar.DbType.MySql,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
},db=>{
db.Aop.OnLogExecuting = (sql, pars) =>
{
logger.LogInformation(sql);
};
});
}
else if(dbtypes.ContainsValue(Define.DBTYPE_PostgreSQL)) //PostgreSQL
{
sqlSugar = new SqlSugarClient (new ConnectionConfig()
{
DbType = SqlSugar.DbType.PostgreSQL,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
},db=>{
db.Aop.OnLogExecuting = (sql, pars) =>
{
logger.LogInformation(sql);
};
});
}
else
{
sqlSugar = new SqlSugarClient (new ConnectionConfig()
{
DbType = SqlSugar.DbType.Oracle,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
},db=>{
db.Aop.OnLogExecuting = (sql, pars) =>
{
logger.LogInformation(sql);
};
});
}
DbType = dbType.Value,
ConnectionString = connectionString,
IsAutoCloseConnection = true,
}, db => { db.Aop.OnLogExecuting = (sql, pars) => { logger.LogInformation(sql); }; });
return sqlSugar;
});