| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using DopInterfacePlatform.Interface;
- using DopInterfacePlatform.Service;
- using Microsoft.EntityFrameworkCore;
- using Swashbuckle.AspNetCore.SwaggerGen;
- using WebApiTest;
- namespace DopInterfacePlatform
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- var builder = WebApplication.CreateBuilder(args);
- // Add services to the container.
- builder.Services.AddControllers();
- builder.Services.AddScoped<ClientIpCheckActionFilter>(container =>
- {
- var loggerFactory = container.GetRequiredService<ILoggerFactory>();
- var logger = loggerFactory.CreateLogger<ClientIpCheckActionFilter>();
- return new ClientIpCheckActionFilter(builder.Configuration["IpWhiteList"], logger);
- });
- // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
- builder.Services.AddEndpointsApiExplorer();
- builder.Services.AddSwaggerGen();
- builder.Services.AddScoped<IJwtService, JwtService>();
- JwtOptions jwtOpt = builder.Configuration.GetSection("JWT").Get<JwtOptions>();
- builder.Services.AddJWTAuthentication(jwtOpt);
- builder.Services.Configure<SwaggerGenOptions>(c =>
- {
- c.AddAuthenticationHeader();
- });
- builder.Services.AddDbContext<DopInterfacePlatformContext>(opt =>
- opt.UseSqlServer(builder.Configuration["ConnectionStrings:todoContext"]));
- builder.Services.AddMvcCore(options =>
- {
- options.Filters.Add<LogFilter>();
- }).AddApiExplorer();
- var app = builder.Build();
- // Configure the HTTP request pipeline.
- app.UseSwagger();
- app.UseSwaggerUI();
- app.UseHttpsRedirection();
- app.UseAuthentication();//注意,一定得先启动这个
- app.UseAuthorization();
- app.UseMiddleware<IpWhiteListMiddleware>(builder.Configuration["IpWhiteList"]);
- app.MapControllers();
- app.Run();
- }
- }
- }
|