138 lines
5.7 KiB
C#
138 lines
5.7 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<RequestDuplicationOptions>(_configuration.GetSection("RequestDuplicationOptions"));
|
||
services.AddOptions().Configure<SystemPacsConfig>(_configuration.GetSection("SystemPacsConfig"));
|
||
services.Configure<IRaCISBasicConfigOption>(_configuration.GetSection("IRaCISBasicConfig"));
|
||
|
||
services.Configure<ServiceVerifyConfigOption>(_configuration.GetSection("BasicSystemConfig"));
|
||
|
||
//ת<><D7AA>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD> <20><>ȡ<EFBFBD><C8A1>ʵ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>();
|
||
|
||
// ע<><D7A2><EFBFBD><EFBFBD>Service <20><>β<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>
|
||
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 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD> <20>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD> ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>handler<65><72>Ӧ<EFBFBD><D3A6>ϵ
|
||
//builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<ConsistencyVerificationHandler>());
|
||
|
||
|
||
|
||
#region <20><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//builder.Services.AddMemoryCache();
|
||
////<2F>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
//builder.Services.Configure<FormOptions>(options =>
|
||
//{
|
||
// options.MultipartBodyLengthLimit = int.MaxValue;
|
||
// options.ValueCountLimit = int.MaxValue;
|
||
// options.ValueLengthLimit = int.MaxValue;
|
||
//});
|
||
//IP <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ߺ<EFBFBD><DFBA><EFBFBD><EFBFBD><EFBFBD>
|
||
//services.AddIpPolicyRateLimitSetup(_configuration);
|
||
// <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ
|
||
//services.AddAuthorizationPolicySetup(_configuration);
|
||
#endregion
|
||
}
|
||
|
||
|
||
}
|
||
|
||
#region Autofac <20><><EFBFBD><EFBFBD>
|
||
//public class AutofacModuleSetup : Autofac.Module
|
||
//{
|
||
// protected override void Load(ContainerBuilder containerBuilder)
|
||
// {
|
||
|
||
// #region byzhouhang 20210917 <20>˴<EFBFBD>ע<EFBFBD>᷺<EFBFBD>Ͳִ<CDB2> <20><><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Domain<69><6E> <20><>Infra.EFcore <20><><EFBFBD><EFBFBD> <20>յIJִ<C4B2><D6B4>ӿڶ<D3BF><DAB6><EFBFBD><EFBFBD> <20>ִ<EFBFBD><D6B4>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
// containerBuilder.RegisterGeneric(typeof(Repository<>))
|
||
// .As(typeof(IRepository<>)).InstancePerLifetimeScope();//ע<>᷺<EFBFBD>Ͳִ<CDB2>
|
||
|
||
// containerBuilder.RegisterType<Repository>().As<IRepository>().InstancePerLifetimeScope();
|
||
|
||
|
||
// #endregion
|
||
|
||
// #region ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>autofac <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>ȡ https://www.cnblogs.com/xwhqwer/p/15320838.html
|
||
|
||
// //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||
// 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();
|
||
|
||
|
||
// //ע<><D7A2>hangfire<72><65><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||
// containerBuilder.RegisterType<ObtainTaskAutoCancelJob>().As<IObtainTaskAutoCancelJob>().InstancePerDependency();
|
||
|
||
// }
|
||
//}
|
||
#endregion
|