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-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<6F><63><EFBFBD><EFBFBD>
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
services.AddIocService(Configuration);
|
|
|
|
|
|
|
2021-10-12 16:52:28 +08:00
|
|
|
|
#region
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
#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<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
services.AddSwaggerService<Program>();
|
|
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
services.AddCorsService();
|
|
|
|
|
|
|
2021-10-17 18:37:07 +08:00
|
|
|
|
#region
|
|
|
|
|
|
//Jwt<77><74>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD>
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
services.AddJwtService();
|
|
|
|
|
|
|
2021-10-12 16:52:28 +08:00
|
|
|
|
#region
|
2021-10-26 15:09:07 +08:00
|
|
|
|
//<2F><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
|
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<69><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
#endregion
|
2021-10-26 15:09:07 +08:00
|
|
|
|
services.AddRedisService();
|
2021-10-12 17:07:27 +08:00
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
|
//RabbitMQ<4D><51><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
#endregion
|
2021-10-26 15:09:07 +08:00
|
|
|
|
services.AddRabbitMQService();
|
2021-10-12 16:52:28 +08:00
|
|
|
|
|
2021-10-23 02:24:18 +08:00
|
|
|
|
|
2021-10-10 16:43:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-12 16:52:28 +08:00
|
|
|
|
#region Autofac<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>
|
|
|
|
|
|
public void ConfigureContainer(ContainerBuilder containerBuilder)
|
|
|
|
|
|
{
|
|
|
|
|
|
#region
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Module<6C><65><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
|
|
|
|
|
#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-10-26 15:09:07 +08:00
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env,IDbContextFactory _DbFactory)
|
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
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>ע<EFBFBD><D7A2>
|
|
|
|
|
|
#endregion
|
2021-10-10 16:43:49 +08:00
|
|
|
|
app.UseDeveloperExceptionPage();
|
2021-10-12 16:52:28 +08:00
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
|
//Swagger<65><72><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
app.UseSwaggerService();
|
2021-10-10 16:43:49 +08:00
|
|
|
|
}
|
2021-10-17 18:37:07 +08:00
|
|
|
|
#region
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ץȡ<D7A5><C8A1><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
app.UseErrorHandlingService();
|
2021-10-10 16:43:49 +08:00
|
|
|
|
|
2021-10-12 16:52:28 +08:00
|
|
|
|
#region
|
|
|
|
|
|
//HttpsRedirectionע<6E><D7A2>
|
|
|
|
|
|
#endregion
|
2021-10-10 16:43:49 +08:00
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
2021-10-12 16:52:28 +08:00
|
|
|
|
#region
|
|
|
|
|
|
//·<><C2B7>ע<EFBFBD><D7A2>
|
|
|
|
|
|
#endregion
|
2021-10-10 16:43:49 +08:00
|
|
|
|
app.UseRouting();
|
2021-10-12 16:52:28 +08:00
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
app.UseCorsService();
|
|
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
|
|
|
|
|
#endregion
|
2021-10-26 15:09:07 +08:00
|
|
|
|
app.UseHealthCheckMiddleware();
|
2021-10-12 16:52:28 +08:00
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
|
//<2F><>Ȩע<C8A8><D7A2>
|
|
|
|
|
|
#endregion
|
2021-10-10 17:52:23 +08:00
|
|
|
|
app.UseAuthentication();
|
2021-10-12 16:52:28 +08:00
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
|
//<2F><>Ȩע<C8A8><D7A2>
|
|
|
|
|
|
#endregion
|
2021-10-10 16:43:49 +08:00
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
2021-10-12 16:52:28 +08:00
|
|
|
|
#region
|
|
|
|
|
|
//Consul<75><6C><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
|
|
|
|
|
#endregion
|
2021-10-26 15:09:07 +08:00
|
|
|
|
app.UseConsulService();
|
2021-10-23 13:41:58 +08:00
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
|
//<2F><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
|
|
|
|
|
#endregion
|
2021-10-26 15:09:07 +08:00
|
|
|
|
app.UseDbSeedInitService(_DbFactory);
|
2021-10-10 17:52:23 +08:00
|
|
|
|
|
2021-10-12 16:52:28 +08:00
|
|
|
|
#region
|
|
|
|
|
|
//Endpointsע<73><D7A2>
|
|
|
|
|
|
#endregion
|
2021-10-10 16:43:49 +08:00
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
|
{
|
|
|
|
|
|
endpoints.MapControllers();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|