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.

92 lines
3.0 KiB
C#

1 year 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.ExcelModule;
using DS.Module.PrintModule;
1 year ago
using DS.Module.Jwt;
using DS.Module.Middleware;
10 months ago
using DS.Module.MultiLanguage;
1 year ago
using DS.Module.SqlSugar;
using DS.Module.Swagger;
using DS.Module.UserModule;
using DS.WMS.MainApi;
using NLog.Web;
using Swashbuckle.AspNetCore.SwaggerUI;
using DS.Module.RedisModule;
1 year ago
var builder = WebApplication.CreateBuilder(args);
var environment = builder.Environment.EnvironmentName;
Console.WriteLine("当前开发环境:" + environment);
//注册配置
11 months ago
builder.Configuration
// .SetBasePath(builder.Environment.ContentRootPath)
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
10 months ago
// .AddJsonFile(path: $"appsettings.{environment}.json", optional: true, reloadOnChange: true)
1 year ago
.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();
11 months ago
builder.Services.AddUserModuleInstall(); //用户服务
builder.Services.AddRedisModuleInstall();//redis
10 months ago
builder.Services.AddSqlSugarInstall();
1 year ago
builder.Services.AddSwaggerInstall();
builder.Services.AddJwtInstall();
11 months ago
builder.Services.AddSaasDbInstall();//分库服务
10 months ago
builder.Services.AddMultiLanguageInstall();//多语言服务
builder.Services.AddExcelModuleInstall();//Excel服务
builder.Services.AddPrintModuleInstall();//Print服务
1 year ago
// 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();
11 months ago
var documentName = AppSetting.app(new string[] { "SwaggerDoc", "ContactName" });
1 year ago
app
.UseSwagger(c => { c.RouteTemplate = "{documentName}/swagger.json"; })
.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/" + documentName + "/swagger.json",
11 months ago
AppSetting.app(new string[] { "SwaggerDoc", "ContactName" }));
c.DocExpansion(DocExpansion.None);//DocExpansion设置为None可折叠所有方法
c.DefaultModelExpandDepth(-1);//-1 可不显示Models
1 year ago
});
//跨域
11 months ago
var policyName =AppSetting.app(new string[] { "Cors", "PolicyName" });
1 year ago
if (!policyName.IsNullOrEmpty())
{
app.UseCors(policyName); //添加跨域中间件
}
app.UseRouting();
app.UseStaticFiles();
10 months ago
//多语言中间件
app.UseMiddleware<MultiLanguageMiddleware>();
// //操作日志中间件
// app.UseMiddleware<OperationLogMiddleware>();
1 year ago
// 先开启认证
app.UseAuthentication();
// 然后是授权中间件
app.UseAuthorization();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
app.Run();