199 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			199 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C#
		
	
	
| 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;
 | ||
| 
 | ||
| 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.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>();
 | ||
|             })
 | ||
|                     .AddDataAnnotationsLocalization(options => {
 | ||
|                         options.DataAnnotationLocalizerProvider = (type, factory) =>
 | ||
|                             factory.Create(typeof(SharedResource));
 | ||
|                     })
 | ||
|                 .AddNewtonsoftJsonSetup(); // NewtonsoftJson ÐòÁл¯  ´¦Àí
 | ||
| 
 | ||
|             //¶¯Ì¬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(typeof(ConsistencyVerificationHandler).Assembly);
 | ||
|             // EasyCaching »º´æ
 | ||
|             services.AddEasyCachingSetup();
 | ||
|             // hangfire  ¶¨Ê±ÈÎÎñ¿ò¼Ü  ÓнçÃæ£¬¸üÓѺÃ~
 | ||
|             services.AddhangfireSetup(_configuration);
 | ||
|             //  QuartZ ¶¨Ê±ÈÎÎñ¿ò¼Ü  ʹÓÃÁËhangfire ÔÝʱ²»Ó㬺óÐøÐèÒª¿ÉÒÔ´ò¿ª£¬ÒѾÅäºÃ
 | ||
|             services.AddQuartZSetup(_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);
 | ||
|             //ת·¢Í·ÉèÖà  »ñÈ¡ÕæÊµIP 
 | ||
|             services.Configure<ForwardedHeadersOptions>(options =>
 | ||
|             {
 | ||
|                 options.ForwardedHeaders =
 | ||
|                     ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
 | ||
|             });
 | ||
|             //DicomÓ°ÏñäÖȾͼƬ  ¿çƽ̨
 | ||
|             services.AddDicomSetup();
 | ||
| 
 | ||
| 
 | ||
|             //services.AddSingleton<IImportResultFilter, ImportResultFilteTest>();
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 | ||
|         public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 | ||
|         {
 | ||
|             //±¾µØ»¯
 | ||
|             app.UseLocalization();
 | ||
| 
 | ||
|             app.UseForwardedHeaders();
 | ||
| 
 | ||
|             //²»ÐèÒª token ·ÃÎʵľ²Ì¬Îļþ  wwwroot css, JavaScript, and images don't require authentication.
 | ||
|             app.UseStaticFiles();
 | ||
| 
 | ||
|             //LogDashboard
 | ||
|             app.UseLogDashboard("/LogDashboard");
 | ||
| 
 | ||
|             //hangfire
 | ||
|             app.UseHangfireConfig(env);
 | ||
| 
 | ||
|             // //ÔÝʱ·ÏÆú
 | ||
|             //app.UseHttpReports();
 | ||
| 
 | ||
|             //ÏÞÁ÷ Öмä¼þ
 | ||
|             //app.UseIpRateLimiting();
 | ||
| 
 | ||
|             //ÏìӦѹËõ
 | ||
|             app.UseResponseCompression();
 | ||
| 
 | ||
|             if (env.IsDevelopment())
 | ||
|             {
 | ||
|                 app.UseDeveloperExceptionPage();
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 //app.UseHsts();
 | ||
|             }
 | ||
|             Console.WriteLine("µ±Ç°»·¾³£º " + env.EnvironmentName);
 | ||
| 
 | ||
|             //app.UseMiddleware<AuthMiddleware>();
 | ||
| 
 | ||
|             // ÌØÊâÒì³£´¦Àí ±ÈÈç 404 
 | ||
|             app.UseStatusCodePagesWithReExecute("/Error/{0}");
 | ||
| 
 | ||
|             SwaggerSetup.Configure(app, env);
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|             //serilog ¼Ç¼ÇëÇóµÄÓû§ÐÅÏ¢
 | ||
|             app.UseSerilogConfig(env);
 | ||
| 
 | ||
|             app.UseRouting();
 | ||
| 
 | ||
|             app.UseAuthentication();
 | ||
|             app.UseAuthorization();
 | ||
| 
 | ||
|             //ÎļþËÅ·þ  ±ØÐë´øToken ·ÃÎÊ
 | ||
|             app.UseIRacisHostStaticFileStore(env);
 | ||
| 
 | ||
|             app.UseEndpoints(endpoints =>
 | ||
|             {
 | ||
|                 endpoints.MapControllers();
 | ||
|             });
 | ||
| 
 | ||
|         }
 | ||
|     }
 | ||
| }
 |