mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 23:13:40 +08:00
优化sqlsugar启动
This commit is contained in:
parent
19fc3bc933
commit
16421f9a8b
@ -174,67 +174,18 @@ namespace OpenAuth.WebApi
|
||||
|
||||
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Configuration["DataProtection"]));
|
||||
|
||||
var sqlsugarTypes = UtilMethods.EnumToDictionary<SqlSugar.DbType>();
|
||||
var dbType = sqlsugarTypes.FirstOrDefault(it =>
|
||||
dbtypes.ToDictionary(u => u.Key, v => v.Value.ToLower()).ContainsValue(it.Key));
|
||||
|
||||
services.AddScoped<ISqlSugarClient>(s =>
|
||||
{
|
||||
|
||||
SqlSugarClient sqlSugar;
|
||||
if(dbtypes.ContainsValue(Define.DBTYPE_SQLSERVER))
|
||||
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.SqlServer,
|
||||
DbType = dbType.Value,
|
||||
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);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
}, db => { db.Aop.OnLogExecuting = (sql, pars) => { logger.LogInformation(sql); }; });
|
||||
return sqlSugar;
|
||||
});
|
||||
|
||||
@ -297,7 +248,8 @@ namespace OpenAuth.WebApi
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.IndexStream = () =>
|
||||
IntrospectionExtensions.GetTypeInfo(GetType()).Assembly.GetManifestResourceStream("OpenAuth.WebApi.index.html");
|
||||
IntrospectionExtensions.GetTypeInfo(GetType()).Assembly
|
||||
.GetManifestResourceStream("OpenAuth.WebApi.index.html");
|
||||
|
||||
foreach (var controller in GetControllers())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user