mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 14:04:41 +08:00
优化sqlsugar启动
This commit is contained in:
parent
19fc3bc933
commit
16421f9a8b
@ -92,7 +92,7 @@ namespace OpenAuth.WebApi
|
|||||||
|
|
||||||
logger.LogInformation($"api doc basepath:{AppContext.BaseDirectory}");
|
logger.LogInformation($"api doc basepath:{AppContext.BaseDirectory}");
|
||||||
foreach (var name in Directory.GetFiles(AppContext.BaseDirectory, "*.*",
|
foreach (var name in Directory.GetFiles(AppContext.BaseDirectory, "*.*",
|
||||||
SearchOption.AllDirectories).Where(f => Path.GetExtension(f).ToLower() == ".xml"))
|
SearchOption.AllDirectories).Where(f => Path.GetExtension(f).ToLower() == ".xml"))
|
||||||
{
|
{
|
||||||
option.IncludeXmlComments(name, includeControllerXmlComments: true);
|
option.IncludeXmlComments(name, includeControllerXmlComments: true);
|
||||||
// logger.LogInformation($"find api file{name}");
|
// logger.LogInformation($"find api file{name}");
|
||||||
@ -173,68 +173,19 @@ namespace OpenAuth.WebApi
|
|||||||
services.AddHttpClient();
|
services.AddHttpClient();
|
||||||
|
|
||||||
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,
|
||||||
{
|
ConnectionString = connectionString,
|
||||||
DbType = SqlSugar.DbType.SqlServer,
|
IsAutoCloseConnection = true,
|
||||||
ConnectionString = connectionString,
|
}, db => { db.Aop.OnLogExecuting = (sql, pars) => { logger.LogInformation(sql); }; });
|
||||||
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);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return sqlSugar;
|
return sqlSugar;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -297,7 +248,8 @@ namespace OpenAuth.WebApi
|
|||||||
app.UseSwaggerUI(c =>
|
app.UseSwaggerUI(c =>
|
||||||
{
|
{
|
||||||
c.IndexStream = () =>
|
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())
|
foreach (var controller in GetControllers())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user