Files
Yi.Admin/Yi.Framework/Yi.Framework.ApiMicroservice/Startup.cs
T

175 lines
4.4 KiB
C#
Raw Normal View History

2021-10-12 16:52:28 +08:00
using Autofac;
2021-10-10 16:43:49 +08:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
2021-10-11 21:50:50 +08:00
using Microsoft.EntityFrameworkCore;
2021-10-10 16:43:49 +08:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
2021-11-03 18:26:13 +08:00
using Yi.Framework.Core;
2021-10-26 15:09:07 +08:00
using Yi.Framework.Model.ModelFactory;
2021-10-12 16:52:28 +08:00
using Yi.Framework.WebCore.MiddlewareExtend;
2021-10-17 18:37:07 +08:00
using Yi.Framework.WebCore.Utility;
2021-10-10 16:43:49 +08:00
2021-10-10 17:30:31 +08:00
namespace Yi.Framework.ApiMicroservice
2021-10-10 16:43:49 +08:00
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
2021-10-13 15:40:56 +08:00
#region
//Ioc配置
#endregion
services.AddIocService(Configuration);
2021-10-30 18:48:58 +08:00
#region
//Quartz任务调度配置
#endregion
services.AddQuartzService();
2021-10-12 16:52:28 +08:00
#region
//控制器+过滤器配置
#endregion
2021-10-17 18:37:07 +08:00
services.AddControllers(optios=> {
//optios.Filters.Add(typeof(CustomExceptionFilterAttribute));
});
2021-10-10 17:52:23 +08:00
2021-10-12 16:52:28 +08:00
#region
//Swagger服务配置
#endregion
services.AddSwaggerService<Program>();
#region
//跨域服务配置
#endregion
services.AddCorsService();
2021-10-17 18:37:07 +08:00
#region
//Jwt鉴权配置
#endregion
services.AddJwtService();
2021-10-12 16:52:28 +08:00
#region
2021-10-26 15:09:07 +08:00
//数据库配置
2021-10-12 16:52:28 +08:00
#endregion
2021-10-26 15:09:07 +08:00
services.AddDbService();
2021-10-23 02:24:18 +08:00
2021-10-12 17:07:27 +08:00
#region
//Redis服务配置
#endregion
2021-10-26 15:09:07 +08:00
services.AddRedisService();
2021-10-12 17:07:27 +08:00
#region
//RabbitMQ服务配置
#endregion
2021-10-26 15:09:07 +08:00
services.AddRabbitMQService();
2021-10-12 16:52:28 +08:00
2021-11-09 18:50:49 +08:00
#region
//ElasticSeach服务配置
#endregion
services.AddElasticSeachService();
2021-11-04 15:15:00 +08:00
#region
//短信服务配置
#endregion
services.AddSMSService();
2021-10-10 16:43:49 +08:00
}
2021-10-12 16:52:28 +08:00
#region Autofac容器注入
public void ConfigureContainer(ContainerBuilder containerBuilder)
{
#region
//交由Module依赖注入
#endregion
containerBuilder.RegisterModule<CustomAutofacModule>();
}
#endregion
2021-10-10 16:43:49 +08:00
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
2021-11-03 18:58:44 +08:00
public void Configure(IApplicationBuilder app, IWebHostEnvironment env,IDbContextFactory _DbFactory, CacheClientDB _cacheClientDB)
2021-10-10 16:43:49 +08:00
{
2021-10-12 16:52:28 +08:00
//if (env.IsDevelopment())
2021-10-10 16:43:49 +08:00
{
2021-10-12 16:52:28 +08:00
#region
//测试页面注入
#endregion
2021-10-10 16:43:49 +08:00
app.UseDeveloperExceptionPage();
2021-10-12 16:52:28 +08:00
#region
//Swagger服务注入
#endregion
app.UseSwaggerService();
2021-10-10 16:43:49 +08:00
}
2021-10-17 18:37:07 +08:00
#region
//错误抓取反馈注入
#endregion
2021-11-03 21:14:58 +08:00
app.UseErrorHandlingService();
2021-10-10 16:43:49 +08:00
2021-11-03 20:28:45 +08:00
#region
//静态文件注入
#endregion
//app.UseStaticFiles();
2021-10-12 16:52:28 +08:00
#region
//HttpsRedirection注入
#endregion
2021-10-10 16:43:49 +08:00
app.UseHttpsRedirection();
2021-10-12 16:52:28 +08:00
#region
//路由注入
#endregion
2021-10-10 16:43:49 +08:00
app.UseRouting();
2021-10-12 16:52:28 +08:00
#region
//跨域服务注入
#endregion
app.UseCorsService();
#region
//健康检查注入
#endregion
2021-10-26 15:09:07 +08:00
app.UseHealthCheckMiddleware();
2021-10-12 16:52:28 +08:00
#region
//鉴权注入
#endregion
2021-10-10 17:52:23 +08:00
app.UseAuthentication();
2021-10-12 16:52:28 +08:00
#region
//授权注入
#endregion
2021-10-10 16:43:49 +08:00
app.UseAuthorization();
2021-10-12 16:52:28 +08:00
#region
//Consul服务注入
#endregion
2021-10-26 15:09:07 +08:00
app.UseConsulService();
2021-10-23 13:41:58 +08:00
#region
//数据库种子注入
#endregion
2021-10-26 15:09:07 +08:00
app.UseDbSeedInitService(_DbFactory);
2021-11-03 18:58:44 +08:00
#region
//redis种子注入
#endregion
app.UseRedisSeedInitService(_cacheClientDB);
2021-11-06 17:10:44 +08:00
2021-10-12 16:52:28 +08:00
#region
//Endpoints注入
#endregion
2021-10-10 16:43:49 +08:00
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
2021-11-04 15:15:00 +08:00
2021-10-10 16:43:49 +08:00
});
}
}
}