172 lines
5.9 KiB
C#
172 lines
5.9 KiB
C#
using Autofac;
|
|
using EasyCaching.Core;
|
|
using EasyCaching.Interceptor.Castle;
|
|
using IRaCIS.Api.Filter;
|
|
using IRaCIS.Application;
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Application.Services;
|
|
using IRaCIS.Core.API.Auth;
|
|
using IRaCIS.Core.Domain.Share;
|
|
using IRaCIS.WX.CoreApi.Utility;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.FileProviders;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Newtonsoft.Json;
|
|
using Serilog;
|
|
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace IRaCIS.Core.API
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
|
|
}
|
|
|
|
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.RegisterType<TokenService>().As<ITokenService>();
|
|
|
|
containerBuilder.RegisterType<LogService>().As<ILogService>().SingleInstance();
|
|
|
|
Assembly domain = Assembly.Load("IRaCIS.Core.Domain");
|
|
containerBuilder.RegisterAssemblyTypes(domain).AsImplementedInterfaces();
|
|
|
|
Assembly domainShare = Assembly.Load("IRaCIS.Core.Domain.Share");
|
|
containerBuilder.RegisterAssemblyTypes(domainShare).AsImplementedInterfaces();
|
|
|
|
Assembly infrastructure = Assembly.Load("IRaCIS.Core.Infra.EFCore");
|
|
containerBuilder.RegisterAssemblyTypes(infrastructure).AsImplementedInterfaces();
|
|
|
|
Assembly application = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "IRaCIS.Core.Application.dll");
|
|
containerBuilder.RegisterAssemblyTypes(application).AsImplementedInterfaces();
|
|
|
|
//containerBuilder.RegisterModule<CustomAutofacModule>();
|
|
|
|
containerBuilder.ConfigureCastleInterceptor();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
|
|
services.AddControllers().AddNewtonsoftJson(options =>
|
|
{
|
|
// 忽略循环引用
|
|
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
|
|
// 不使用驼峰
|
|
options.SerializerSettings.ContractResolver = new NullToEmptyStringResolver(); //new DefaultContractResolver();// new NullToEmptyStringResolver();
|
|
// 设置时间格式
|
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|
});
|
|
|
|
services.Configure<FormOptions>(options =>
|
|
{
|
|
options.ValueCountLimit = int.MaxValue;
|
|
options.ValueLengthLimit = int.MaxValue;
|
|
});
|
|
if (SystemConfig.OpenLog)
|
|
{
|
|
services.AddControllers(options =>
|
|
{
|
|
options.Filters.Add<LogActionFilter>();
|
|
});
|
|
}
|
|
|
|
services.AddLogging();
|
|
|
|
#region EasyCaching
|
|
|
|
services.AddEasyCaching(options =>
|
|
{
|
|
options.UseInMemory();
|
|
});
|
|
services.ConfigureCastleInterceptor(options => options.CacheProviderName = EasyCachingConstValue.DefaultInMemoryName);
|
|
|
|
#endregion
|
|
|
|
|
|
//MiniProfilerConfigure.ConfigureMiniProfiler(services);
|
|
|
|
AuthConfigure.ConfigureAuth(services, Configuration);
|
|
|
|
AutoMapperConfigure.ConfigureSwagger(services);
|
|
EFConfigure.ConfigureEF(services, Configuration);
|
|
SwaggerConfigure.ConfigureSwagger(services);
|
|
|
|
//services.Configure<IISServerOptions>(options =>
|
|
//{
|
|
// options.MaxRequestBodySize = int.MaxValue;
|
|
//});
|
|
|
|
|
|
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
////不能放在静态方法中
|
|
//app.UseSwaggerUI(options =>
|
|
//{
|
|
// options.IndexStream = () =>
|
|
// GetType().GetTypeInfo().Assembly
|
|
// .GetManifestResourceStream("IRaCIS.Core.API.index.html");
|
|
//});
|
|
//app.UseMiniProfiler();
|
|
}
|
|
app.UseDeveloperExceptionPage();
|
|
SwaggerConfigure.Configure(app, env);
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseStaticFiles(new StaticFileOptions()
|
|
{
|
|
FileProvider = new PhysicalFileProvider(
|
|
Path.Combine(Path.GetFullPath(Path.Combine(env.ContentRootPath, "..")), @"UploadFile")),
|
|
RequestPath = new PathString("/UploadFile"),
|
|
ServeUnknownFileTypes = true,
|
|
DefaultContentType = "application/octet-stream"
|
|
|
|
});
|
|
|
|
//app.UseMiddleware<AuthMiddleware>();
|
|
|
|
|
|
//app.Use(async (context, next) =>
|
|
//{
|
|
// context.Request.EnableBuffering();
|
|
// await next();
|
|
//});
|
|
|
|
app.UseRouting();
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
});
|
|
|
|
}
|
|
}
|
|
}
|