137 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			137 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C#
		
	
	
| using IP2Region.Net.Abstractions;
 | ||
| using IP2Region.Net.XDB;
 | ||
| using IRaCIS.Core.Application.BackGroundJob;
 | ||
| using IRaCIS.Core.Application.Helper;
 | ||
| using IRaCIS.Core.Application.Service;
 | ||
| using IRaCIS.Core.Domain.Share;
 | ||
| using IRaCIS.Core.Infra.EFCore;
 | ||
| using Microsoft.AspNetCore.Builder;
 | ||
| using Microsoft.AspNetCore.HttpOverrides;
 | ||
| using Microsoft.AspNetCore.SignalR;
 | ||
| using Microsoft.Extensions.Configuration;
 | ||
| using Microsoft.Extensions.DependencyInjection;
 | ||
| using Panda.DynamicWebApi;
 | ||
| using System;
 | ||
| using System.IO;
 | ||
| using System.Linq;
 | ||
| using System.Reflection;
 | ||
| 
 | ||
| namespace IRaCIS.Core.API;
 | ||
| 
 | ||
| 
 | ||
| public static class ServiceCollectionSetup
 | ||
| {
 | ||
|     public static void ConfigureServices(this IServiceCollection services, IConfiguration _configuration)
 | ||
|     {
 | ||
|         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"));
 | ||
|         services.AddOptions().Configure<IRCEncreptOption>(_configuration.GetSection("EncrypteResponseConfig"));
 | ||
|         services.AddOptions().Configure<SystemPacsConfig>(_configuration.GetSection("SystemPacsConfig"));
 | ||
|         services.Configure<IRaCISBasicConfigOption>(_configuration.GetSection("IRaCISBasicConfig"));
 | ||
| 
 | ||
|         services.Configure<ServiceVerifyConfigOption>(_configuration.GetSection("BasicSystemConfig"));
 | ||
| 
 | ||
|         //ת·¢Í·ÉèÖà  »ñÈ¡ÕæÊµIP 
 | ||
|         services.Configure<ForwardedHeadersOptions>(options =>
 | ||
|         {
 | ||
|             options.ForwardedHeaders =
 | ||
|                 ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
 | ||
|         });
 | ||
| 
 | ||
|         services.AddSingleton<IUserIdProvider, IRaCISUserIdProvider>();
 | ||
|         services.AddSingleton<ISearcher>(new Searcher(CachePolicy.Content, Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources, "ip2region.xdb")));
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|         services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
 | ||
|         services.AddScoped<IRepository, Repository>();
 | ||
| 
 | ||
|         services.AddScoped<IObtainTaskAutoCancelJob, ObtainTaskAutoCancelJob>();
 | ||
| 
 | ||
|         // ×¢²áÒÔService ½áβµÄ·þÎñ
 | ||
|         services.Scan(scan => scan
 | ||
|             .FromAssemblies(typeof(BaseService).Assembly)
 | ||
|             .AddClasses(classes => classes.Where(t => t.Name.Contains("Service")))
 | ||
|             .AsImplementedInterfaces()
 | ||
|             .WithScopedLifetime());
 | ||
| 
 | ||
|         #region Register Controllers
 | ||
| 
 | ||
|         // Register all controllers in the assembly that implement IDynamicWebApi
 | ||
|         services.Scan(scan => scan
 | ||
|             .FromAssemblies(typeof(BaseService).Assembly)
 | ||
|             .AddClasses(classes => classes.AssignableTo<IDynamicWebApi>())
 | ||
|             .AsSelf()
 | ||
|             .WithScopedLifetime());
 | ||
| 
 | ||
|         #endregion
 | ||
| 
 | ||
| 
 | ||
|         // MediatR ½ø³ÌÄÚÏûÏ¢ ʼþ½âñî  ´Ó³ÌÐò¼¯ÖÐ ×¢²áÃüÁîºÍhandler¶ÔÓ¦¹ØÏµ
 | ||
|         //builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<ConsistencyVerificationHandler>());
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|         #region  ÀúÊ··ÏÆúÅäÖÃ
 | ||
|         //builder.Services.AddMemoryCache();
 | ||
|         ////ÉÏ´«ÏÞÖÆ ÅäÖÃ
 | ||
|         //builder.Services.Configure<FormOptions>(options =>
 | ||
|         //{
 | ||
|         //    options.MultipartBodyLengthLimit = int.MaxValue;
 | ||
|         //    options.ValueCountLimit = int.MaxValue;
 | ||
|         //    options.ValueLengthLimit = int.MaxValue;
 | ||
|         //});
 | ||
|         //IP ÏÞÁ÷ ¿ÉÉèÖð×Ãûµ¥ »òÕߺÚÃûµ¥
 | ||
|         //services.AddIpPolicyRateLimitSetup(_configuration);
 | ||
|         // Óû§ÀàÐÍ ²ßÂÔÊÚȨ
 | ||
|         //services.AddAuthorizationPolicySetup(_configuration);
 | ||
|         #endregion
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
| }
 | ||
| 
 | ||
| #region Autofac ·ÏÆú
 | ||
| //public class AutofacModuleSetup : Autofac.Module
 | ||
| //{
 | ||
| //    protected override void Load(ContainerBuilder containerBuilder)
 | ||
| //    {
 | ||
| 
 | ||
| //        #region  byzhouhang  20210917  ´Ë´¦×¢²á·ºÐͲִ¢ ¿ÉÒÔ¼õÉÙDomain²ã ºÍInfra.EFcore Á½²ã ¿ÕµÄ²Ö´¢½Ó¿Ú¶¨ÒåºÍ ²Ö´¢Îļþ¶¨Òå
 | ||
| 
 | ||
| //        containerBuilder.RegisterGeneric(typeof(Repository<>))
 | ||
| //            .As(typeof(IRepository<>)).InstancePerLifetimeScope();//×¢²á·ºÐͲִ¢
 | ||
| 
 | ||
| //        containerBuilder.RegisterType<Repository>().As<IRepository>().InstancePerLifetimeScope();
 | ||
| 
 | ||
| 
 | ||
| //        #endregion
 | ||
| 
 | ||
| //        #region Ö¸¶¨¿ØÖÆÆ÷Ò²ÓÉautofac À´½øÐÐʵÀý»ñÈ¡ https://www.cnblogs.com/xwhqwer/p/15320838.html
 | ||
| 
 | ||
| //        //»ñÈ¡ËùÓпØÖÆÆ÷ÀàÐͲ¢Ê¹ÓÃÊôÐÔ×¢Èë
 | ||
| //        containerBuilder.RegisterAssemblyTypes(typeof(BaseService).Assembly)
 | ||
| //            .Where(type => typeof(IDynamicWebApi).IsAssignableFrom(type))
 | ||
| //            .PropertiesAutowired();
 | ||
| 
 | ||
| //        #endregion
 | ||
| 
 | ||
| 
 | ||
| //        Assembly application = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "IRaCIS.Core.Application.dll");
 | ||
| //        containerBuilder.RegisterAssemblyTypes(application).Where(t => t.FullName.Contains("Service"))
 | ||
| //            .PropertiesAutowired().AsImplementedInterfaces();
 | ||
| 
 | ||
| //        //containerBuilder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
 | ||
| //        //containerBuilder.RegisterType<UserInfo>().As<IUserInfo>().InstancePerLifetimeScope();
 | ||
| 
 | ||
| 
 | ||
| //        //×¢²áhangfireÈÎÎñ  ÒÀÀµ×¢Èë
 | ||
| //        containerBuilder.RegisterType<ObtainTaskAutoCancelJob>().As<IObtainTaskAutoCancelJob>().InstancePerDependency();
 | ||
| 
 | ||
| //    }
 | ||
| //}
 | ||
| #endregion
 |