清理旧的写法
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
d15a9945de
commit
3537ccf3cd
|
@ -1,112 +0,0 @@
|
||||||
using System;
|
|
||||||
using Autofac.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Serilog;
|
|
||||||
using MediatR;
|
|
||||||
using IRaCIS.Core.Application.MediatR.Handlers;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MassTransit;
|
|
||||||
using MassTransit.NewIdProviders;
|
|
||||||
using System.IO;
|
|
||||||
using IRaCIS.Core.Domain.Share;
|
|
||||||
using IRaCIS.Core.Infra.EFCore;
|
|
||||||
using IRaCIS.Core.Application.Helper;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace IRaCIS.Core.API
|
|
||||||
{
|
|
||||||
public class Program1
|
|
||||||
{
|
|
||||||
public readonly string environment;
|
|
||||||
public static async Task Main(string[] args)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//以配置文件为准,否则 从url中取环境值(服务以命令行传递参数启动,配置文件配置了就不需要传递环境参数)
|
|
||||||
var config = new ConfigurationBuilder()
|
|
||||||
.AddEnvironmentVariables()
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
var enviromentName = config["ASPNETCORE_ENVIRONMENT"];
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(enviromentName))
|
|
||||||
{
|
|
||||||
|
|
||||||
var index = Array.IndexOf(args, "--env");
|
|
||||||
enviromentName = index > -1
|
|
||||||
? args[index + 1]
|
|
||||||
: "Development";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Dicom 浏览
|
|
||||||
//ImageManager.SetImplementation(WinFormsImageManager.Instance);
|
|
||||||
|
|
||||||
var host = CreateHostBuilder(args)
|
|
||||||
.UseEnvironment(enviromentName) //命令行传入环境
|
|
||||||
.ConfigureAppConfiguration((hostContext, config) =>
|
|
||||||
{
|
|
||||||
|
|
||||||
//Console.WriteLine(hostContext.HostingEnvironment.EnvironmentName);
|
|
||||||
config.AddJsonFile("appsettings.json", false, true)
|
|
||||||
.AddJsonFile($"appsettings.{enviromentName}.json", false, true);
|
|
||||||
})
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
//// Serilog
|
|
||||||
SerilogExtension.AddSerilogSetup(enviromentName, host.Services);
|
|
||||||
|
|
||||||
Log.Logger.Warning($"当前环境:{enviromentName}");
|
|
||||||
|
|
||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
||||||
{
|
|
||||||
Log.Logger.Warning($"当前部署平台环境:windows");
|
|
||||||
}
|
|
||||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
||||||
{
|
|
||||||
Log.Logger.Warning($"当前部署平台环境:linux");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.Logger.Warning($"当前部署平台环境:OSX or FreeBSD");
|
|
||||||
}
|
|
||||||
|
|
||||||
NewId.SetProcessIdProvider(new CurrentProcessIdProvider());
|
|
||||||
|
|
||||||
|
|
||||||
host.Run();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
|
|
||||||
Log.Logger.Error(e.InnerException is null ? e.Message + e.StackTrace : e.InnerException?.Message + e.InnerException?.StackTrace);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
||||||
Host.CreateDefaultBuilder(args)
|
|
||||||
.UseWindowsService()
|
|
||||||
.ConfigureWebHostDefaults(webBuilder =>
|
|
||||||
{
|
|
||||||
webBuilder.ConfigureKestrel((context, options) =>
|
|
||||||
{
|
|
||||||
//设置应用服务器Kestrel请求体最大为1GB // if don't set default value is: 30 MB
|
|
||||||
options.Limits.MaxRequestBodySize = long.MaxValue;
|
|
||||||
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(30);
|
|
||||||
options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(20);
|
|
||||||
|
|
||||||
});
|
|
||||||
//webBuilder.UseSerilog();//在宿主机启动的时候配置serilog,与微软ILogger进行整合
|
|
||||||
webBuilder.UseStartup<Startup>();
|
|
||||||
}).UseSerilog()
|
|
||||||
.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,251 +0,0 @@
|
||||||
using Autofac;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using System;
|
|
||||||
using IRaCIS.Core.Application.Filter;
|
|
||||||
using LogDashboard;
|
|
||||||
using MediatR;
|
|
||||||
using IRaCIS.Core.Application.MediatR.Handlers;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using AspNetCoreRateLimit;
|
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
|
||||||
using IRaCIS.Core.Infra.EFCore;
|
|
||||||
using System.Globalization;
|
|
||||||
using Microsoft.AspNetCore.Localization;
|
|
||||||
using Localization;
|
|
||||||
using Magicodes.ExporterAndImporter.Core.Filters;
|
|
||||||
using IRaCIS.Core.Application.MediatR.CommandAndQueries;
|
|
||||||
using IRaCIS.Core.Infra.EFCore.Common;
|
|
||||||
using Invio.Extensions.Authentication.JwtBearer;
|
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
using IRaCIS.Core.Domain.Share;
|
|
||||||
using Microsoft.AspNetCore.StaticFiles;
|
|
||||||
using IRaCIS.Core.Application.Helper;
|
|
||||||
using IRaCIS.Application.Services.BackGroundJob;
|
|
||||||
|
|
||||||
namespace IRaCIS.Core.API
|
|
||||||
{
|
|
||||||
public class Startup
|
|
||||||
{
|
|
||||||
public Startup(IConfiguration configuration)
|
|
||||||
{
|
|
||||||
_configuration = configuration;
|
|
||||||
}
|
|
||||||
public ILogger<Startup> _logger { get; }
|
|
||||||
|
|
||||||
public IConfiguration _configuration { get; }
|
|
||||||
|
|
||||||
//// ConfigureContainer is where you can register things directly
|
|
||||||
//// with Autofac. This runs after ConfigureServices so the things
|
|
||||||
//// here will override registrations made in ConfigureServices.
|
|
||||||
//// Don't build the container; that gets done for you by the factory.
|
|
||||||
// for castle
|
|
||||||
public void ConfigureContainer(ContainerBuilder containerBuilder)
|
|
||||||
{
|
|
||||||
containerBuilder.RegisterModule<AutofacModuleSetup>();
|
|
||||||
|
|
||||||
#region Test
|
|
||||||
//containerBuilder.RegisterType<ClinicalDataService>().PropertiesAutowired().InstancePerLifetimeScope();//注册仓储
|
|
||||||
|
|
||||||
//var container = containerBuilder.Build();
|
|
||||||
|
|
||||||
//// Now you can resolve services using Autofac. For example,
|
|
||||||
//// this line will execute the lambda expression registered
|
|
||||||
//// to the IConfigReader service.
|
|
||||||
//using (var scope = container.BeginLifetimeScope())
|
|
||||||
//{
|
|
||||||
// var reader = scope.Resolve<BaseService>();
|
|
||||||
|
|
||||||
// var test = scope.Resolve<ClinicalDataService>();
|
|
||||||
// var test2 = scope.Resolve<IClinicalDataService>();
|
|
||||||
|
|
||||||
// var test3 = scope.Resolve<IEFUnitOfWork<IRaCISDBContext>>();
|
|
||||||
//}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
|
||||||
{
|
|
||||||
//健康检查
|
|
||||||
services.AddHealthChecks();
|
|
||||||
//本地化
|
|
||||||
services.AddJsonLocalization(options => options.ResourcesPath = "Resources");
|
|
||||||
|
|
||||||
// 异常、参数统一验证过滤器、Json序列化配置、字符串参数绑型统一Trim()
|
|
||||||
services.AddControllers(options =>
|
|
||||||
{
|
|
||||||
//options.Filters.Add<LogActionFilter>();
|
|
||||||
options.Filters.Add<ModelActionFilter>();
|
|
||||||
options.Filters.Add<ProjectExceptionFilter>();
|
|
||||||
options.Filters.Add<UnitOfWorkFilter>();
|
|
||||||
|
|
||||||
if (_configuration.GetSection("BasicSystemConfig").GetValue<bool>("OpenLoginLimit"))
|
|
||||||
{
|
|
||||||
options.Filters.Add<LimitUserRequestAuthorization>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
.AddNewtonsoftJsonSetup(); // NewtonsoftJson 序列化 处理
|
|
||||||
|
|
||||||
services.AddOptions().Configure<SystemEmailSendConfig>( _configuration.GetSection("SystemEmailSendConfig"));
|
|
||||||
services.AddOptions().Configure<ServiceVerifyConfigOption>(_configuration.GetSection("BasicSystemConfig"));
|
|
||||||
services.AddOptions().Configure<AliyunOSSOptions>(_configuration.GetSection("AliyunOSS"));
|
|
||||||
services.AddOptions().Configure<ObjectStoreServiceOptions>(_configuration.GetSection("ObjectStoreService"));
|
|
||||||
|
|
||||||
|
|
||||||
//动态WebApi + UnifiedApiResultFilter 省掉控制器代码
|
|
||||||
services.AddDynamicWebApiSetup();
|
|
||||||
//AutoMapper
|
|
||||||
services.AddAutoMapperSetup();
|
|
||||||
//EF ORM QueryWithNoLock
|
|
||||||
services.AddEFSetup(_configuration);
|
|
||||||
//Http 响应压缩
|
|
||||||
services.AddResponseCompressionSetup();
|
|
||||||
//Swagger Api 文档
|
|
||||||
services.AddSwaggerSetup();
|
|
||||||
//JWT Token 验证
|
|
||||||
services.AddJWTAuthSetup(_configuration);
|
|
||||||
|
|
||||||
|
|
||||||
// MediatR 进程内消息 事件解耦 从程序集中 注册命令和handler对应关系
|
|
||||||
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<ConsistencyVerificationHandler>());
|
|
||||||
// EasyCaching 缓存
|
|
||||||
services.AddEasyCachingSetup(_configuration);
|
|
||||||
|
|
||||||
//services.AddDistributedMemoryCache();
|
|
||||||
|
|
||||||
// hangfire 定时任务框架 有界面,更友好~
|
|
||||||
services.AddhangfireSetup(_configuration);
|
|
||||||
|
|
||||||
|
|
||||||
// 保护上传文件
|
|
||||||
//services.AddStaticFileAuthorizationSetup();
|
|
||||||
|
|
||||||
|
|
||||||
////HttpReports 暂时废弃
|
|
||||||
//services.AddHttpReports().AddHttpTransport();
|
|
||||||
//Serilog 日志可视化 LogDashboard日志
|
|
||||||
services.AddLogDashboardSetup();
|
|
||||||
//上传限制 配置
|
|
||||||
services.Configure<FormOptions>(options =>
|
|
||||||
{
|
|
||||||
options.MultipartBodyLengthLimit = int.MaxValue;
|
|
||||||
options.ValueCountLimit = int.MaxValue;
|
|
||||||
options.ValueLengthLimit = int.MaxValue;
|
|
||||||
});
|
|
||||||
//IP 限流 可设置白名单 或者黑名单
|
|
||||||
//services.AddIpPolicyRateLimitSetup(_configuration);
|
|
||||||
// 用户类型 策略授权
|
|
||||||
//services.AddAuthorizationPolicySetup(_configuration);
|
|
||||||
|
|
||||||
services.AddJsonConfigSetup(_configuration);
|
|
||||||
//转发头设置 获取真实IP
|
|
||||||
services.Configure<ForwardedHeadersOptions>(options =>
|
|
||||||
{
|
|
||||||
options.ForwardedHeaders =
|
|
||||||
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
|
||||||
});
|
|
||||||
//Dicom影像渲染图片 跨平台
|
|
||||||
services.AddDicomSetup();
|
|
||||||
|
|
||||||
// 实时应用
|
|
||||||
services.AddSignalR();
|
|
||||||
|
|
||||||
|
|
||||||
services.AddSingleton<IUserIdProvider, IRaCISUserIdProvider>();
|
|
||||||
|
|
||||||
//services.AddSingleton<IImportResultFilter, ImportResultFilteTest>();
|
|
||||||
|
|
||||||
services.AddMemoryCache();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
||||||
public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
//本地化
|
|
||||||
app.UseLocalization();
|
|
||||||
|
|
||||||
app.UseForwardedHeaders();
|
|
||||||
|
|
||||||
//响应压缩
|
|
||||||
app.UseResponseCompression();
|
|
||||||
|
|
||||||
//app.UseCors(t => t.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
|
|
||||||
|
|
||||||
//不需要 token 访问的静态文件 wwwroot css, JavaScript, and images don't require authentication.
|
|
||||||
app.UseStaticFiles();
|
|
||||||
|
|
||||||
app.UseMiddleware<MultiDiskStaticFilesMiddleware>();
|
|
||||||
|
|
||||||
//LogDashboard
|
|
||||||
app.UseLogDashboard("/LogDashboard");
|
|
||||||
|
|
||||||
//hangfire
|
|
||||||
app.UseHangfireConfig(env);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////限流 中间件
|
|
||||||
//app.UseIpRateLimiting();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
|
||||||
{
|
|
||||||
app.UseDeveloperExceptionPage();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//app.UseHsts();
|
|
||||||
}
|
|
||||||
Console.WriteLine("当前环境: " + env.EnvironmentName);
|
|
||||||
|
|
||||||
|
|
||||||
// 特殊异常处理 比如 404
|
|
||||||
app.UseStatusCodePagesWithReExecute("/Error/{0}");
|
|
||||||
|
|
||||||
SwaggerSetup.Configure(app, env);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////serilog 记录请求的用户信息
|
|
||||||
app.UseSerilogConfig(env);
|
|
||||||
|
|
||||||
app.UseRouting();
|
|
||||||
|
|
||||||
app.UseCors(t => t.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
|
|
||||||
|
|
||||||
//app.UseIRacisHostStaticFileStore(env);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.UseAuthentication();
|
|
||||||
app.UseAuthorization();
|
|
||||||
|
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
|
||||||
{
|
|
||||||
endpoints.MapControllers();
|
|
||||||
|
|
||||||
endpoints.MapHub<UploadHub>("/UploadHub");
|
|
||||||
|
|
||||||
endpoints.MapHealthChecks("/health");
|
|
||||||
});
|
|
||||||
|
|
||||||
var hangfireJobService = app.ApplicationServices.GetRequiredService<IIRaCISHangfireJob>();
|
|
||||||
|
|
||||||
await hangfireJobService.InitHangfireJobTaskAsync();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue