|
|
|
@ -26,7 +26,6 @@ using SqlSugar;
|
|
|
|
|
using Swashbuckle.AspNetCore.SwaggerUI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenAuth.WebApi
|
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
@ -46,7 +45,10 @@ namespace OpenAuth.WebApi
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddHttpContextAccessor();
|
|
|
|
|
services.AddSingleton<MqttClientManager>(provider => new MqttClientManager());
|
|
|
|
|
|
|
|
|
|
#region log4net
|
|
|
|
|
|
|
|
|
|
//在startup中需要强制创建log4net
|
|
|
|
|
//var loggerFactory = LoggerFactory.Create(builder => { builder.AddLog4Net(); });
|
|
|
|
|
//ILogger logger = loggerFactory.CreateLogger<Startup>();
|
|
|
|
@ -56,9 +58,11 @@ namespace OpenAuth.WebApi
|
|
|
|
|
loggingBuilder.ClearProviders();
|
|
|
|
|
loggingBuilder.AddLog4Net();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region identityServer
|
|
|
|
|
|
|
|
|
|
var identityServer =
|
|
|
|
|
((ConfigurationSection)Configuration.GetSection("AppSetting:IdentityServerUrl")).Value;
|
|
|
|
|
if (!string.IsNullOrEmpty(identityServer))
|
|
|
|
@ -73,9 +77,11 @@ namespace OpenAuth.WebApi
|
|
|
|
|
options.Audience = "openauthapi";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region MiniProfiler
|
|
|
|
|
|
|
|
|
|
// 添加MiniProfiler服务
|
|
|
|
|
//services.AddMiniProfiler(options =>
|
|
|
|
|
//{
|
|
|
|
@ -89,13 +95,16 @@ namespace OpenAuth.WebApi
|
|
|
|
|
// options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();
|
|
|
|
|
// // options.IgnoredPaths.Add("/swagger/");
|
|
|
|
|
//}).AddEntityFramework(); //显示SQL语句及耗时
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region swagger
|
|
|
|
|
|
|
|
|
|
//添加swagger
|
|
|
|
|
services.AddSwaggerGen(option =>
|
|
|
|
|
{
|
|
|
|
|
#region 注释
|
|
|
|
|
|
|
|
|
|
//foreach (var controller in GetControllers())
|
|
|
|
|
//{
|
|
|
|
|
// var groupname = GetSwaggerGroupName(controller);
|
|
|
|
@ -114,7 +123,9 @@ namespace OpenAuth.WebApi
|
|
|
|
|
// option.IncludeXmlComments(name, includeControllerXmlComments: true);
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
option.CustomSchemaIds(type => type.FullName);
|
|
|
|
|
option.SwaggerDoc("v1", new OpenApiInfo
|
|
|
|
|
{
|
|
|
|
@ -147,27 +158,29 @@ namespace OpenAuth.WebApi
|
|
|
|
|
|
|
|
|
|
// option.OperationFilter<GlobalHttpHeaderOperationFilter>(); // 添加httpHeader参数
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region AppSetting
|
|
|
|
|
|
|
|
|
|
services.Configure<AppSetting>(Configuration.GetSection("AppSetting"));
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 限制文件大小
|
|
|
|
|
services.Configure<KestrelServerOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Limits.MaxRequestBodySize = long.MaxValue;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
services.Configure<KestrelServerOptions>(options => { options.Limits.MaxRequestBodySize = long.MaxValue; });
|
|
|
|
|
services.Configure<FormOptions>(x =>
|
|
|
|
|
{
|
|
|
|
|
x.ValueLengthLimit = int.MaxValue;
|
|
|
|
|
x.MultipartBodyLengthLimit = long.MaxValue;
|
|
|
|
|
x.MemoryBufferThreshold = int.MaxValue;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Controllers
|
|
|
|
|
|
|
|
|
|
services.AddControllers(option =>
|
|
|
|
|
{
|
|
|
|
|
option.Filters.Add<OpenAuthFilter>();
|
|
|
|
@ -194,10 +207,13 @@ namespace OpenAuth.WebApi
|
|
|
|
|
//options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
|
|
|
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region MemoryCache
|
|
|
|
|
|
|
|
|
|
services.AddMemoryCache();
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Cors
|
|
|
|
@ -223,16 +239,15 @@ namespace OpenAuth.WebApi
|
|
|
|
|
// .AllowAnyMethod()
|
|
|
|
|
// .AllowAnyHeader());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region SqlSugar
|
|
|
|
|
|
|
|
|
|
////没有直接 using SqlSugar,因为如果引用命名空间的话,会和Microsoft的一个GetTypeInfo存在二义性,所以就直接这么使用了
|
|
|
|
|
services.AddScoped<ISqlSugarClient>(s =>
|
|
|
|
|
{
|
|
|
|
|
StaticConfig.CustomSnowFlakeFunc = () =>
|
|
|
|
|
{
|
|
|
|
|
return Yitter.IdGenerator.YitIdHelper.NextId();
|
|
|
|
|
};
|
|
|
|
|
StaticConfig.CustomSnowFlakeFunc = () => { return Yitter.IdGenerator.YitIdHelper.NextId(); };
|
|
|
|
|
|
|
|
|
|
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
|
|
|
|
{
|
|
|
|
@ -278,24 +293,34 @@ namespace OpenAuth.WebApi
|
|
|
|
|
});
|
|
|
|
|
return sqlSugar;
|
|
|
|
|
});
|
|
|
|
|
services.AddScoped<SqlSugar.ISugarUnitOfWork<SugarDbContext>>(s => new SqlSugar.SugarUnitOfWork<SugarDbContext>(s.GetService<ISqlSugarClient>()));
|
|
|
|
|
services.AddScoped<SqlSugar.ISugarUnitOfWork<SugarDbContext>>(s =>
|
|
|
|
|
new SqlSugar.SugarUnitOfWork<SugarDbContext>(s.GetService<ISqlSugarClient>()));
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region HttpClient
|
|
|
|
|
|
|
|
|
|
services.AddHttpClient();
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region DataProtection
|
|
|
|
|
|
|
|
|
|
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Configuration["DataProtection"]));
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Quartz
|
|
|
|
|
|
|
|
|
|
//设置定时启动的任务
|
|
|
|
|
services.AddHostedService<QuartzService>();
|
|
|
|
|
//services.AddHostedService<QuartzService>();
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region SignalR
|
|
|
|
|
|
|
|
|
|
services.AddSignalR();
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -327,7 +352,8 @@ namespace OpenAuth.WebApi
|
|
|
|
|
//可以在这里为静态文件添加其他http头信息,默认添加跨域信息
|
|
|
|
|
ctx.Context.Response.Headers["Access-Control-Allow-Origin"] = "*";
|
|
|
|
|
},
|
|
|
|
|
ContentTypeProvider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider(new Dictionary<string, string>
|
|
|
|
|
ContentTypeProvider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider(
|
|
|
|
|
new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ ".amr", "audio/AMR" },
|
|
|
|
|
{ ".mp3", "audio/mpeg" },
|
|
|
|
|