using Furion; using Myshipping.Core; using Myshipping.Core.Service; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using System; using System.Net; using System.Net.Http; using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.Unicode; using Yitter.IdGenerator; using Furion.Templates; using Furion.Logging; using System.Collections.Generic; using Newtonsoft.Json.Serialization; using Newtonsoft.Json; using Myshipping.Application.ConfigOption; namespace Myshipping.Web.Core; [AppStartup(9)] public class Startup : AppStartup { public void ConfigureServices(IServiceCollection services) { services.AddBStyle(m => m.UseDefault()); services.AddConfigurableOptions(); services.AddConfigurableOptions(); services.AddConfigurableOptions(); services.AddConfigurableOptions(); services.AddConfigurableOptions(); services.AddConfigurableOptions(); services.AddConfigurableOptions(); services.AddConfigurableOptions(); services.AddConfigurableOptions(); services.AddConfigurableOptions(); #region 上传文件大小限制 long maxRequestBodySize = Convert.ToInt64(App.Configuration["MaxRequestBodySize"]); services.Configure(options => { options.Limits.MaxRequestBodySize = maxRequestBodySize; }); services.Configure(options => { options.MaxRequestBodySize = maxRequestBodySize; }); services.Configure(o => { o.MultipartBodyLengthLimit = maxRequestBodySize; }); #endregion services.AddResponseCompression(); services.SqlSugarScopeConfigure(); services.AddJwt(enableGlobalAuthorize: true); services.AddCorsAccessor(); // 配置远程请求 services.AddRemoteRequest(option => { // 配置天气预报GZIP option.AddHttpClient("wthrcdn", c => { c.BaseAddress = new Uri("http://wthrcdn.etouch.cn/"); }).ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip }); }); services.AddControllersWithViews() .AddMvcFilter() .AddMvcFilter() .AddMvcFilter() .AddInjectWithUnifyResult() .AddNewtonsoftJson(options => { // 首字母小写(驼峰样式) options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // 时间格式化 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; // 忽略循环引用 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // 忽略空值 options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; }); services.AddViewEngine(); services.AddSignalR(); // 设置雪花id的workerId,确保每个实例workerId都应不同 var workerId = ushort.Parse(App.GetOptions().WorkerId); YitIdHelper.SetIdGenerator(new IdGeneratorOptions { WorkerId = workerId }); // 开启自启动定时任务 App.GetService().StartTimerJob(); // 注册EventBus服务 services.AddEventBus(builder => { // 注册 Log 日志订阅者 builder.AddSubscriber(); //钉钉消息 builder.AddSubscriber(); }); #region 缓存 //船公司 App.GetService().GetAllCarrier(); //船公司映射 App.GetService().GetAllMappingCarrier(); //船名 App.GetService().GetAllVessel(); //船名映射 App.GetService().GetAllMappingVessel(); //场站映射 App.GetService().GetAllMappingYard(); //船代 App.GetService().GetAllForwarder(); //场站 App.GetService().GetAllYard(); //起始港 App.GetService().GetAllPortload(); //目的港 App.GetService().GetAllPort(); //包装 App.GetService().GetAllPackage(); //运输方式 App.GetService().GetAllService(); //箱型 App.GetService().GetAllCtn(); //箱型映射 App.GetService().GetAllMappingCtn(); //付费方式 App.GetService().GetAllFrt(); //付费方式映射 App.GetService().GetAllMappingFrt(); //起始港映射 App.GetService().GetAllMappingPortLoad(); //目的港映射 App.GetService().GetAllMappingPort(); //包装映射 App.GetService().GetAllMappingPackage(); //运输服务映射 App.GetService().GetAllMappingService(); //缓存EDI数据 App.GetService().CacheData(); //缓存字典数据 App.GetService().CacheData(); //租户参数 App.GetService().CacheData(); #endregion } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } // 添加状态码拦截中间件 app.UseUnifyResultStatusCodes(); app.UseHttpsRedirection(); // 强制https app.UseStaticFiles(); app.UseRouting(); app.UseCorsAccessor(); app.UseAuthentication(); app.UseAuthorization(); app.UseResponseCompression(); app.UseInject(string.Empty); app.UseEndpoints(endpoints => { endpoints.MapHub("/hubs/chathub"); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); } }