wanshenmean
2026-03-11 a8f45091019012eeafec563913dee71cda3d9790
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using Autofac;
using Autofac.Core;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.FileProviders;
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;
using WIDESEAWCS_Core.Core;
using WIDESEAWCS_Core.Extensions;
using WIDESEAWCS_Core.Filter;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_Core.Middlewares;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.QuartzExtensions;
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�����÷�������
 
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()).ConfigureContainer<ContainerBuilder>(builder =>
{
    builder.RegisterModule(new AutofacModuleRegister());//���нӿڲ�ķ���ע��
    builder.RegisterModule(new QuartzJobAutofacModuleRegister());
    builder.RegisterModule<AutofacPropertityModuleReg>();//
}).ConfigureAppConfiguration((hostingContext, config) =>
{
    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.AddRedisSetup(builder.Configuration);//Redis缓存
builder.Services.AddSqlsugarSetup();//SqlSugar ��������
builder.Services.AddInitializationHostServiceSetup();//Ӧ�ó�ʼ������ע��
builder.Services.AddHostedService<SeedDataHostedService>();//��ʼ�����ݿ�
 
builder.Services.AddDbSetup();//Db ��������
 
builder.Services.AddScoped<QuartzJobCreateDataTabel>();//������� ע�봴��QuartzJob���ݿ����
builder.Services.AddHostedService<QuartzJobDataTableHostedService>();//������� ӳ��QuartzJob���ݿ��
 
builder.Services.AddWebSocketSetup();
 
builder.Services.AddAutoMapperSetup();
 
builder.Services.AddCorsSetup();
 
builder.Services.AddMiniProfilerSetup();
 
builder.Services.AddSwaggerSetup();
 
builder.Services.AddJobSetup();//������� ע�뷴���ȡ��������
 
builder.Services.AddHttpContextSetup();
 
builder.Services.AddHostedService<QuartzJobHostedService>();//������� ��������
builder.Services.AddSingleton<TcpSocketServer>();
builder.Services.AddHostedService<SocketServerHostedService>();
 
builder.Services.AddMvc(options =>
{
    options.Filters.Add(typeof(ApiAuthorizeFilter));
    options.Filters.Add(typeof(ActionExecuteFilter));
    options.Filters.Add(typeof(CustomAuthorizeFilter));
});
 
builder.Services.AddScoped<HttpClientHelper>();
 
builder.Services.AddAuthorizationSetup();
 
builder.Services.AddIpPolicyRateLimitSetup(builder.Configuration);//IPLimit���� ��������
 
builder.Services.AddScoped<UseServiceDIAttribute>();
 
builder.Services.AddSession();
 
builder.Services.AddHttpClient();
 
builder.Services.AddControllers(o =>
{
    o.Filters.Add(typeof(GlobalExceptionsFilter));//ȫ���쳣
})
.AddNewtonsoftJson(options =>
{
    options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
    //options.SerializerSettings.ContractResolver = new DefaultContractResolver();
    options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
    options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
    options.SerializerSettings.NullValueHandling = NullValueHandling.Include;
    options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
    options.SerializerSettings.Converters.Add(new StringEnumConverter());
});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
 
builder.Services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
 
 
var app = builder.Build();
 
// 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.UseIpLimitMiddle();
app.UseApiLogMiddleware();
 
app.UseCors(AppSettings.Get(new string[] { "Cors", "PolicyName" }));
 
DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions();
defaultFilesOptions.DefaultFileNames.Clear();
defaultFilesOptions.DefaultFileNames.Add("index.html");
app.UseDefaultFiles(defaultFilesOptions);
app.UseMiddleware<HttpRequestMiddleware>();
app.UseStaticFiles();
 
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(App.WebHostEnvironment.WebRootPath)
});
app.UseCookiePolicy();
app.UseStatusCodePages();
 
app.UseRouting();
 
app.UseAuthentication();
app.UseAuthorization();
 
app.MapControllers();
 
app.Run();