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
16421f9a8b
commit
115c79bd9c
@ -94,47 +94,18 @@ namespace OpenAuth.IdentityServer
|
|||||||
options.UseOracle(connectionString, o=>o.UseOracleSQLCompatibility("11")));
|
options.UseOracle(connectionString, o=>o.UseOracleSQLCompatibility("11")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sqlsugarTypes = UtilMethods.EnumToDictionary<SqlSugar.DbType>();
|
||||||
|
var sugarDbtype = sqlsugarTypes.FirstOrDefault(it =>
|
||||||
|
dbtypes.ToDictionary(u => u.Key, v => v.Value.ToLower()).ContainsValue(it.Key));
|
||||||
|
|
||||||
services.AddScoped<ISqlSugarClient>(s =>
|
services.AddScoped<ISqlSugarClient>(s =>
|
||||||
{
|
{
|
||||||
|
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
||||||
SqlSugarClient sqlSugar;
|
|
||||||
if(dbtypes.ContainsValue(Define.DBTYPE_SQLSERVER))
|
|
||||||
{
|
{
|
||||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
DbType = sugarDbtype.Value,
|
||||||
{
|
|
||||||
DbType = SqlSugar.DbType.SqlServer,
|
|
||||||
ConnectionString = connectionString,
|
ConnectionString = connectionString,
|
||||||
IsAutoCloseConnection = true,
|
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return sqlSugar;
|
return sqlSugar;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -101,67 +101,18 @@ namespace OpenAuth.Mvc
|
|||||||
|
|
||||||
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Configuration["DataProtection"]));
|
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 =>
|
services.AddScoped<ISqlSugarClient>(s =>
|
||||||
{
|
{
|
||||||
|
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
||||||
SqlSugarClient sqlSugar;
|
|
||||||
if(dbtypes.ContainsValue(Define.DBTYPE_SQLSERVER))
|
|
||||||
{
|
{
|
||||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
DbType = dbType.Value,
|
||||||
{
|
|
||||||
DbType = SqlSugar.DbType.SqlServer,
|
|
||||||
ConnectionString = connectionString,
|
ConnectionString = connectionString,
|
||||||
IsAutoCloseConnection = true,
|
IsAutoCloseConnection = true,
|
||||||
},db=>{
|
}, db => { db.Aop.OnLogExecuting = (sql, pars) => { logger.LogInformation(sql); }; });
|
||||||
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);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return sqlSugar;
|
return sqlSugar;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user