You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
12 months ago
|
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.Swagger;
|
||
|
using DS.Module.UserModule;
|
||
|
using DS.WMS.MainApi;
|
||
|
using NLog.Web;
|
||
|
|
||
|
var builder = WebApplication.CreateBuilder(args);
|
||
|
var environment = builder.Environment.EnvironmentName;
|
||
|
Console.WriteLine("当前开发环境:" + environment);
|
||
|
//注册配置
|
||
|
builder.Configuration.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
|
||
|
.AddJsonFile(path: $"appsettings.{environment}.json", optional: true, reloadOnChange: true)
|
||
|
.Build();
|
||
|
builder.Configuration.AddEnvironmentVariables();
|
||
|
builder.Logging.AddNLog("nlog.config");
|
||
|
// Add services to the container.
|
||
|
//Autofac注入
|
||
|
builder.Host
|
||
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
||
|
.ConfigureContainer<ContainerBuilder>(builder => { builder.RegisterModule(new AutofacModuleRegister()); });
|
||
|
|
||
|
builder.Services.AddAppWebInstal();
|
||
|
builder.Services.AddCorsInstall();
|
||
|
builder.Services.AddSqlsugarInstall();
|
||
|
builder.Services.AddSwaggerInstall();
|
||
|
builder.Services.AddUserModuleInstall(); //用户服务
|
||
|
builder.Services.AddJwtInstall();
|
||
|
|
||
|
// builder.Services.AddEndpointsApiExplorer();
|
||
|
// builder.Services.AddSwaggerGen();
|
||
|
|
||
|
var app = builder.Build();
|
||
|
|
||
|
// Configure the HTTP request pipeline.
|
||
|
// if (app.Environment.IsDevelopment())
|
||
|
// {
|
||
|
// app.UseSwagger();
|
||
|
// app.UseSwaggerUI();
|
||
|
// }
|
||
|
//swagger
|
||
|
// app.UseSwagger();
|
||
|
var documentName = AppSetting.Configuration["SwaggerDoc:ContactName"];
|
||
|
app
|
||
|
.UseSwagger(c => { c.RouteTemplate = "{documentName}/swagger.json"; })
|
||
|
.UseSwaggerUI(c =>
|
||
|
{
|
||
|
c.SwaggerEndpoint("/" + documentName + "/swagger.json",
|
||
|
AppSetting.Configuration["SwaggerDoc:ContactName"]);
|
||
|
});
|
||
|
//跨域
|
||
|
var policyName = AppSetting.Configuration["Cors:PolicyName"];
|
||
|
if (!policyName.IsNullOrEmpty())
|
||
|
{
|
||
|
app.UseCors(policyName); //添加跨域中间件
|
||
|
}
|
||
|
|
||
|
app.UseRouting();
|
||
|
|
||
|
app.UseStaticFiles();
|
||
|
|
||
|
// 先开启认证
|
||
|
app.UseAuthentication();
|
||
|
// 然后是授权中间件
|
||
|
app.UseAuthorization();
|
||
|
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
||
|
|
||
|
app.Run();
|