简化startup
This commit is contained in:
@@ -28,92 +28,19 @@ public class Startup : AppStartup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.ConfigureMvcController();
|
||||
|
||||
// SqlSugar
|
||||
services.SqlSugarConfigure();
|
||||
|
||||
// Jwt处理程序
|
||||
services.AddJwt<JwtHandler>(enableGlobalAuthorize: true);
|
||||
|
||||
// 跨域
|
||||
services.AddCorsAccessor();
|
||||
//services.SqlSugarConfigure();
|
||||
services.ConfigureSqlSugar();
|
||||
|
||||
// 注册EventBus服务
|
||||
services.AddEventBus(options =>
|
||||
{
|
||||
//// 创建连接工厂
|
||||
//var factory = new RabbitMQ.Client.ConnectionFactory
|
||||
//{
|
||||
// // 设置主机名
|
||||
// HostName = "192.168.0.232",
|
||||
|
||||
// // 用户名
|
||||
// UserName = "jnpf",
|
||||
|
||||
// // 密码
|
||||
// Password = "jnpf@2019",
|
||||
//};
|
||||
|
||||
//// 创建默认内存通道事件源对象,可自定义队列路由key,比如这里是 eventbus
|
||||
//var rbmqEventSourceStorer = new RabbitMQEventSourceStorer(factory, "eventbus", 3000);
|
||||
|
||||
//// 替换默认事件总线存储器
|
||||
//options.ReplaceStorer(serviceProvider =>
|
||||
//{
|
||||
// return rbmqEventSourceStorer;
|
||||
//});
|
||||
|
||||
options.UseUtcTimestamp = false;
|
||||
|
||||
// 不启用事件日志
|
||||
options.LogEnabled = false;
|
||||
|
||||
// 事件执行器(失败重试)
|
||||
options.AddExecutor<RetryEventHandlerExecutor>();
|
||||
});
|
||||
services.ConfigureEventBus();
|
||||
|
||||
// 注册远程请求
|
||||
services.AddRemoteRequest();
|
||||
|
||||
services.AddConfigurableOptions<CacheOptions>();
|
||||
services.AddConfigurableOptions<ConnectionStringsOptions>();
|
||||
services.AddConfigurableOptions<TenantOptions>();
|
||||
|
||||
services.AddControllers()
|
||||
.AddMvcFilter<RequestActionFilter>()
|
||||
.AddInjectWithUnifyResult<RESTfulResultProvider>()
|
||||
.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null)
|
||||
.AddNewtonsoftJson(options =>
|
||||
{
|
||||
// 默认命名规则
|
||||
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
|
||||
// 设置时区为 UTC
|
||||
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
|
||||
|
||||
// 格式化json输出的日期格式
|
||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
// 忽略空值
|
||||
// options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
|
||||
|
||||
// 忽略循环引用
|
||||
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
|
||||
// 格式化json输出的日期格式为时间戳
|
||||
options.SerializerSettings.Converters.Add(new NewtonsoftDateTimeJsonConverter());
|
||||
});
|
||||
|
||||
// 配置Nginx转发获取客户端真实IP
|
||||
// 注1:如果负载均衡不是在本机通过 Loopback 地址转发请求的,一定要加上options.KnownNetworks.Clear()和options.KnownProxies.Clear()
|
||||
// 注2:如果设置环境变量 ASPNETCORE_FORWARDEDHEADERS_ENABLED 为 True,则不需要下面的配置代码
|
||||
services.Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
options.ForwardedHeaders = ForwardedHeaders.All;
|
||||
options.KnownNetworks.Clear();
|
||||
options.KnownProxies.Clear();
|
||||
});
|
||||
|
||||
// 视图引擎
|
||||
// 视图引擎
|
||||
services.AddViewEngine();
|
||||
|
||||
// 任务调度
|
||||
@@ -128,16 +55,9 @@ public class Startup : AppStartup
|
||||
// 微信
|
||||
services.AddSenparcGlobalServices(App.Configuration) // Senparc.CO2NET 全局注册
|
||||
.AddSenparcWeixinServices(App.Configuration); // Senparc.Weixin 注册(如果使用Senparc.Weixin SDK则添加)
|
||||
services.AddSession();
|
||||
services.AddMemoryCache(); // 使用本地缓存必须添加
|
||||
|
||||
services.LoggingConfigure();
|
||||
|
||||
services.AddUnitOfWork<SqlSugarUnitOfWork>();
|
||||
|
||||
services.OSSServiceConfigure();
|
||||
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
services.ConfigureLogging();
|
||||
services.ConfigureOSSService();
|
||||
|
||||
services.AddSchedule();
|
||||
|
||||
@@ -153,10 +73,8 @@ public class Startup : AppStartup
|
||||
app.UseStaticFiles();
|
||||
|
||||
#region 微信
|
||||
|
||||
IRegisterService register = RegisterService.Start(senparcSetting.Value).UseSenparcGlobal();//启动 CO2NET 全局注册,必须!
|
||||
register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value);//微信全局注册,必须!
|
||||
|
||||
#endregion
|
||||
|
||||
app.UseWebSockets();
|
||||
|
||||
Reference in New Issue
Block a user