From 3ec3e0c1913bc902dbbcaeae2959897df6212ec2 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期四, 28 十一月 2024 15:41:23 +0800
Subject: [PATCH] 更新
---
WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs | 30 ++++++++++++++++--------------
1 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs b/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
index 4f4e913..30d606b 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
@@ -21,6 +21,7 @@
using Autofac.Core;
using WIDESEAWCS_QuartzJob.QuartzExtensions;
using Microsoft.AspNetCore.Builder;
+using WIDESEAWCS_Server.Filter;
var builder = WebApplication.CreateBuilder(args);
@@ -34,20 +35,20 @@
hostingContext.Configuration.ConfigureApplication();
config.Sources.Clear();
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);
-}); ;
+});
builder.ConfigureApplication();
-
// 2、配置服务
builder.Services.AddSingleton(new AppSettings(builder.Configuration));//注册
builder.Services.AddAllOptionRegister();//读取配置文件
builder.Services.AddMemoryCacheSetup();//缓存
builder.Services.AddSqlsugarSetup();//SqlSugar 启动服务
-builder.Services.AddInitializationHostServiceSetup();//应用初始化服务注入
+//builder.Services.AddHostedService<SeedDataHostedService>();//初始化数据库
+
builder.Services.AddDbSetup();//Db 启动服务
-builder.Services.AddScoped<QuartzJobCreateDataTabel>();
-builder.Services.AddHostedService<QuartzJobDataTableHostedService>();
+//builder.Services.AddScoped<QuartzJobCreateDataTabel>();//任务调度 注入创建QuartzJob数据库表类
+//builder.Services.AddHostedService<QuartzJobDataTableHostedService>();//任务调度 映射QuartzJob数据库表
builder.Services.AddAutoMapperSetup();
@@ -57,16 +58,17 @@
builder.Services.AddSwaggerSetup();
-builder.Services.AddJobSetup();//任务调度 启动服务
+builder.Services.AddJobSetup();//任务调度 注入反射获取依赖对象
builder.Services.AddHttpContextSetup();
-builder.Services.AddHostedService<QuartzJobHostedService>();
+builder.Services.AddHostedService<QuartzJobHostedService>();//任务调度 启动服务
builder.Services.AddMvc(options =>
{
options.Filters.Add(typeof(ApiAuthorizeFilter));
options.Filters.Add(typeof(ActionExecuteFilter));
+ options.Filters.Add(typeof(CustomAuthorizeFilter));
});
builder.Services.AddAuthorizationSetup();
@@ -106,20 +108,20 @@
app.UseMiniProfiler();//性能分析器
app.ConfigureApplication();//配置文件
app.UseApplicationSetup();//启动配置
+
+app.UseAllServicesMiddle(builder.Services);
+
app.UseSession();
-if (app.Environment.IsDevelopment())
+//if (app.Environment.IsDevelopment())
{
- //todo
- //app.UseSwaggerAuthorized();
- app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("WIDESEAWCS_Server.index.html"));
+ app.UseSwaggerAuthorized();
+ app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("WIDESEAWCS_Server.index.html") ?? throw new Exception("未找到WIDESEAWCS_Server.index.html文件"));
}//判断是否需要打开swagger
app.UseIpLimitMiddle();
app.UseApiLogMiddleware();
-//todo
-//app.UseRecordAccessLogsMiddle();
-app.UseCors(AppSettings.app(new string[] { "Cors", "PolicyName" }));
+app.UseCors(AppSettings.Get(new string[] { "Cors", "PolicyName" }));
DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions();
defaultFilesOptions.DefaultFileNames.Clear();
--
Gitblit v1.9.3