using Autofac; using Autofac.Extensions.DependencyInjection; using DS.Module.AutofacModule; using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.Core.ServiceExtensions; using DS.Module.Jwt; using DS.Module.SqlSugar; using DS.Module.UserModule; using DS.WMS.AppApi; using NLog.Extensions.Logging; using Microsoft.AspNetCore.Authentication.JwtBearer; var builder = WebApplication.CreateBuilder(args); builder.Logging.AddNLog("nlog.config"); //Autofac注入 builder.Host .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureContainer(builder => { builder.RegisterModule(new AutofacModuleRegister()); }); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddAppWebInstal(); builder.Services.AddAnyCorsInstall(); builder.Services.AddSqlsugarInstall(); builder.Services.AddUserModuleInstall();//用户服务 builder.Services.AddJwtInstall(); // // 以下是加入了JWT身份认证 // builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => // { // options.Authority = "http://localhost:3005"; // options.RequireHttpsMetadata = false; // options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters // { // ValidateAudience = false // }; // }); var app = builder.Build(); // Configure the HTTP request pipeline. app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", AppSetting.Configuration["SwaggerDoc:Version"]); }); //跨域 var policyName = AppSetting.Configuration["Cors:PolicyName"]; if (!policyName.IsNullOrEmpty()) { app.UseCors(policyName); //添加跨域中间件 } app.UseRouting(); app.UseStaticFiles(); // app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.Run();