using System.Text.Json; using Base; using Common; using Extensions; using Filters; using Infrastructure; using Infrastructure.Model; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.FileProviders; using Middleware; using MySystem; using Services; using SummerBoot.Core; using Util; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); //注入HttpContextAccessor builder.Services.AddSingleton(); //IPRatelimit // builder.Services.AddIPRate(builder.Configuration); builder.Services.AddSession(); builder.Services.AddHttpContextAccessor(); builder.Services.AddCors(option => option.AddPolicy("cors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().SetIsOriginAllowed(_ => true))); builder.Services.Configure(x => x.AllowSynchronousIO = true).Configure(x => x.AllowSynchronousIO = true); //绑定整个对象到Model上 builder.Services.Configure(builder.Configuration); // builder.Configuration.AddJsonFile("iprate.json"); //配置文件 builder.Services.AddSingleton(new AppSettings(builder.Configuration)); //请求大小限制 builder.Services.AddRequestLimit(builder.Configuration); //注册REDIS 服务 var openRedis = builder.Configuration["RedisServer:open"]; if (openRedis == "1") { RedisServer.Initalize(); } //配置文件 builder.Services.AddSingleton(new AppSettings(builder.Configuration)); //app服务注册 builder.Services.AddAppService(); builder.Services.AddMvc(options => { options.Filters.Add(typeof(GlobalActionMonitor));//全局注册 options.Filters.Add(typeof(AuthorizationFilter)); }) .AddJsonOptions(options => { //options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString; options.JsonSerializerOptions.WriteIndented = true; options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeConverter()); options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeNullConverter()); options.JsonSerializerOptions.Converters.Add(new StringConverter()); //PropertyNamingPolicy属性用于前端传过来的属性的格式策略,目前内置的仅有一种策略CamelCase options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; //options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;//属性可以忽略大小写格式,开启后性能会降低 }); builder.Services.AddSummerBoot(); builder.Services.AddSummerBootFeign(); var app = builder.Build(); InternalApp.ServiceProvider = app.Services; InternalApp.Configuration = builder.Configuration; InternalApp.WebHostEnvironment = app.Environment; //初始化db builder.Services.AddDb(app.Environment); var workId = builder.Configuration["workId"].ParseToInt(); if (app.Environment.IsDevelopment()) { workId += 1; } SnowFlakeSingle.WorkId = workId; //使用全局异常中间件 app.UseMiddleware(); app.Use(next => new RequestDelegate( async context => { context.Request.EnableBuffering(); await next(context); } )); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { } app.UseStaticFiles(); app.UseCors(); app.UseHttpsRedirection(); app.UseAuthorization(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{Id?}"); }); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.MapControllers(); app.Urls.Add("http://*:5802"); // PrizeDo.sendPrize(1, "{\"PosSn\":\"00005702880118401003\"}"); // PrizeDo.sendPrize(1, "{\"PosSn\":\"00003102722406215502730\"}"); // PrizeDo.sendPrize(4, "{\"PosSn\":\"CS00000000015859\"}"); // PrizeDo.sendPrize(5, "{\"PosSn\":\"00000302T1NL90664172\"}"); // PrizeDo.sendPrize(6, "{\"PosSn\":\"1152131239\"}"); // PrizeDo.sendPrize("KXS_MALL_ORDER_PRIZE", "{\"order_id\":\"319698\"}"); // PrizeDo.sendPrize(7, "{\"OrderNo\":\"BM2024090817330511847441249\"}"); // PrizeDo.sendPrize(7, "{\"OrderNo\":\"BM2024090817360962275551251\"}"); RabbitMQClient.Instance.Start(); // PrizeDo.sendPrize("{\"prize_tag\":\"1\",\"content\":\"{\\\"PosSn\\\":\\\"00002402045980195457\\\"}\"}"); app.Run();