From bfd4fd8e4a05a681ec10a47992294cf752a764c4 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 02 三月 2026 15:10:58 +0800
Subject: [PATCH] 添加Redis服务与缓存增强
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs | 54 +++++++++++++++++++++++++++++++-----------------------
1 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
index a7cb7e0..a33363b 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
@@ -1,5 +1,3 @@
-using System.Reflection;
-using System.Text;
using Autofac;
using Autofac.Core;
using Autofac.Extensions.DependencyInjection;
@@ -11,6 +9,9 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
+using System.Reflection;
+using System.Text;
+using WIDESEA_Core;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Authorization;
using WIDESEAWCS_Core.BaseServices;
@@ -25,14 +26,16 @@
using WIDESEAWCS_QuartzJob.Seed;
using WIDESEAWCS_Server.Filter;
using WIDESEAWCS_Server.HostedService;
+using WIDESEAWCS_Tasks.SocketServer;
+using WIDESEAWCS_RedisService.Extensions;
using WIDESEAWCS_WCSServer.Filter;
var builder = WebApplication.CreateBuilder(args);
-// 1、配置服务容器
+// 1锟斤拷锟斤拷锟矫凤拷锟斤拷锟斤拷锟斤拷
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()).ConfigureContainer<ContainerBuilder>(builder =>
{
- builder.RegisterModule(new AutofacModuleRegister());//带有接口层的服务注入
+ builder.RegisterModule(new AutofacModuleRegister());//锟斤拷锟叫接口诧拷姆锟斤拷锟阶拷锟�
builder.RegisterModule(new QuartzJobAutofacModuleRegister());
builder.RegisterModule<AutofacPropertityModuleReg>();//
}).ConfigureAppConfiguration((hostingContext, config) =>
@@ -43,20 +46,21 @@
});
builder.ConfigureApplication();
-// 2、配置服务
-builder.Services.AddSingleton(new AppSettings(builder.Configuration));//注册
-builder.Services.AddAllOptionRegister();//读取配置文件
+// 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.AddMemoryCacheSetup();//锟斤拷锟斤拷
+builder.Services.AddRedisSetup(builder.Configuration);//Redis缂撳瓨
+builder.Services.AddSqlsugarSetup();//SqlSugar 锟斤拷锟斤拷锟斤拷锟斤拷
+builder.Services.AddInitializationHostServiceSetup();//应锟矫筹拷始锟斤拷锟斤拷锟斤拷注锟斤拷
+builder.Services.AddHostedService<SeedDataHostedService>();//锟斤拷始锟斤拷锟斤拷锟捷匡拷
-builder.Services.AddDbSetup();//Db 启动服务
+builder.Services.AddDbSetup();//Db 锟斤拷锟斤拷锟斤拷锟斤拷
-builder.Services.AddScoped<QuartzJobCreateDataTabel>();//任务调度 注入创建QuartzJob数据库表类
-builder.Services.AddHostedService<QuartzJobDataTableHostedService>();//任务调度 映射QuartzJob数据库表
+builder.Services.AddScoped<QuartzJobCreateDataTabel>();//锟斤拷锟斤拷锟斤拷锟� 注锟诫创锟斤拷QuartzJob锟斤拷锟捷匡拷锟斤拷锟�
+builder.Services.AddHostedService<QuartzJobDataTableHostedService>();//锟斤拷锟斤拷锟斤拷锟� 映锟斤拷QuartzJob锟斤拷锟捷匡拷锟�
builder.Services.AddWebSocketSetup();
@@ -68,11 +72,13 @@
builder.Services.AddSwaggerSetup();
-builder.Services.AddJobSetup();//任务调度 注入反射获取依赖对象
+builder.Services.AddJobSetup();//锟斤拷锟斤拷锟斤拷锟� 注锟诫反锟斤拷锟饺★拷锟斤拷锟斤拷锟斤拷锟�
builder.Services.AddHttpContextSetup();
-builder.Services.AddHostedService<QuartzJobHostedService>();//任务调度 启动服务
+builder.Services.AddHostedService<QuartzJobHostedService>();//锟斤拷锟斤拷锟斤拷锟� 锟斤拷锟斤拷锟斤拷锟斤拷
+builder.Services.AddSingleton<TcpSocketServer>();
+builder.Services.AddHostedService<SocketServerHostedService>();
builder.Services.AddMvc(options =>
{
@@ -81,9 +87,11 @@
options.Filters.Add(typeof(CustomAuthorizeFilter));
});
+builder.Services.AddScoped<HttpClientHelper>();
+
builder.Services.AddAuthorizationSetup();
-builder.Services.AddIpPolicyRateLimitSetup(builder.Configuration);//IPLimit限流 启动服务
+builder.Services.AddIpPolicyRateLimitSetup(builder.Configuration);//IPLimit锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷
builder.Services.AddScoped<UseServiceDIAttribute>();
@@ -93,7 +101,7 @@
builder.Services.AddControllers(o =>
{
- o.Filters.Add(typeof(GlobalExceptionsFilter));//全局异常
+ o.Filters.Add(typeof(GlobalExceptionsFilter));//全锟斤拷锟届常
})
.AddNewtonsoftJson(options =>
{
@@ -114,17 +122,17 @@
var app = builder.Build();
-// 3、配置中间件
-app.UseMiniProfiler();//性能分析器
-app.ConfigureApplication();//配置文件
-app.UseApplicationSetup();//启动配置
+// 3锟斤拷锟斤拷锟斤拷锟叫硷拷锟�
+app.UseMiniProfiler();//锟斤拷锟杰凤拷锟斤拷锟斤拷
+app.ConfigureApplication();//锟斤拷锟斤拷锟侥硷拷
+app.UseApplicationSetup();//锟斤拷锟斤拷锟斤拷锟斤拷
app.UseAllServicesMiddle(builder.Services);
app.UseSession();
app.UseSwaggerAuthorized();
-app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("WIDESEAWCS_Server.index.html") ?? throw new Exception("未找到WIDESEAWCS_Server.index.html文件"));
+app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("WIDESEAWCS_Server.index.html") ?? throw new Exception("未锟揭碉拷WIDESEAWCS_Server.index.html锟侥硷拷"));
app.UseIpLimitMiddle();
app.UseApiLogMiddleware();
--
Gitblit v1.9.3