162 lines
5.6 KiB
C#
162 lines
5.6 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.Features;
|
||
using Microsoft.Extensions.Configuration;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using Microsoft.Extensions.Hosting;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
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 =>
|
||
{
|
||
// <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
|
||
// <20><>ʹ<EFBFBD><CAB9><EFBFBD>շ<EFBFBD>
|
||
options.SerializerSettings.ContractResolver = new NullToEmptyStringResolver(); //new DefaultContractResolver();// new NullToEmptyStringResolver();
|
||
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʽ
|
||
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())
|
||
{
|
||
////<2F><><EFBFBD>ܷ<EFBFBD><DCB7>ھ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//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(Directory.GetCurrentDirectory(), @"UploadFile")),
|
||
// RequestPath = new PathString("/UploadFile")
|
||
//});
|
||
|
||
//app.UseMiddleware<AuthMiddleware>();
|
||
|
||
|
||
//app.Use(async (context, next) =>
|
||
//{
|
||
// context.Request.EnableBuffering();
|
||
// await next();
|
||
//});
|
||
|
||
app.UseRouting();
|
||
app.UseAuthentication();
|
||
app.UseAuthorization();
|
||
|
||
app.UseEndpoints(endpoints =>
|
||
{
|
||
endpoints.MapControllers();
|
||
});
|
||
}
|
||
}
|
||
}
|