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.

80 lines
2.4 KiB
C#

11 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;
11 months ago
using DS.Module.MultiLanguage;
5 months ago
using DS.Module.RedisModule;
11 months ago
using DS.Module.SqlSugar;
using DS.Module.Swagger;
using DS.Module.UserModule;
using DS.WMS.AdminApi;
using NLog.Web;
using Swashbuckle.AspNetCore.SwaggerUI;
1 year ago
var builder = WebApplication.CreateBuilder(args);
11 months ago
var environment = builder.Environment.EnvironmentName;
//注册配置
builder.Configuration
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
.Build();
builder.Configuration.AddEnvironmentVariables();
builder.Logging.AddNLog("nlog.config");
1 year ago
// Add services to the container.
11 months ago
//Autofac注入
builder.Host
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureContainer<ContainerBuilder>(builder => { builder.RegisterModule(new AutofacModuleRegister()); });
builder.Services.AddAppWebInstal();
builder.Services.AddCorsInstall();
11 months ago
builder.Services.AddUserModuleInstall(); //用户服务
builder.Services.AddRedisModuleInstall();//redis
10 months ago
builder.Services.AddSqlSugarInstall();
11 months ago
builder.Services.AddSwaggerInstall();
builder.Services.AddJwtInstall();
11 months ago
builder.Services.AddSaasDbInstall();//分库服务
11 months ago
builder.Services.AddMultiLanguageInstall();//多语言服务
1 year ago
var app = builder.Build();
// Configure the HTTP request pipeline.
11 months ago
// if (app.Environment.IsDevelopment())
// {
// app.UseSwagger();
// app.UseSwaggerUI();
// }
//swagger
// app.UseSwagger();
var documentName = AppSetting.app(new string[] { "SwaggerDoc", "ContactName" });
app
.UseSwagger(c => { c.RouteTemplate = "{documentName}/swagger.json"; })
.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/" + documentName + "/swagger.json",
AppSetting.app(new string[] { "SwaggerDoc", "ContactName" }));
c.DocExpansion(DocExpansion.None);//DocExpansion设置为None可折叠所有方法
c.DefaultModelExpandDepth(-1);//-1 可不显示Models
11 months ago
});
//跨域
var policyName =AppSetting.app(new string[] { "Cors", "PolicyName" });
if (!policyName.IsNullOrEmpty())
1 year ago
{
11 months ago
app.UseCors(policyName); //添加跨域中间件
1 year ago
}
11 months ago
app.UseRouting();
1 year ago
11 months ago
app.UseStaticFiles();
// 先开启认证
app.UseAuthentication();
// 然后是授权中间件
app.UseAuthorization();
11 months ago
11 months ago
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
11 months ago
11 months ago
app.Run();