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.

85 lines
2.2 KiB
C#

2 years ago
using Autofac;
using Autofac.Extensions.DependencyInjection;
using DS.Module.AutofacModule;
2 years ago
using DS.Module.Core;
using DS.Module.Core.Extensions;
2 years ago
using DS.Module.Core.Modules;
2 years ago
using DS.Module.Core.ServiceExtensions;
using DS.Module.Jwt;
2 years ago
using DS.Module.SqlSugar;
2 years ago
using DS.Module.Swagger;
2 years ago
using DS.Module.User;
using DS.WMS.Core.DBSeed;
using DS.WMS.WebApi;
using Microsoft.AspNetCore.StaticFiles;
using NLog.Web;
2 years ago
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddNLog("nlog.config");
2 years ago
// Add services to the container.
//Autofac注入
builder.Host
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureContainer<ContainerBuilder>(builder =>
{
builder.RegisterModule(new AutofacModuleRegister());
});
2 years ago
2 years ago
2 years ago
builder.Services.AddAppWebInstal();
builder.Services.AddCorsInstall();
builder.Services.AddSqlsugarInstall();
builder.Services.AddSwaggerInstall();
builder.Services.AddJwtInstall();
// builder.Services.AddApplication<DSAppWebModule>();
2 years ago
2 years ago
// 3、配置中间件
2 years ago
var app = builder.Build();
2 years ago
// app.InitializeApplication();
//if (app.Environment.IsDevelopment())
//{
// app.UseDeveloperExceptionPage();
//}
//else
//{
// app.UseExceptionHandler("/Error");
// //app.UseHsts();
//}
//swagger
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();
2 years ago
// app.UseStaticFiles();
//文件
app.UseStaticFiles(new StaticFileOptions
{
//FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory()),
//设置不限制content-type 该设置可以下载所有类型的文件,但是不建议这么设置,因为不安全
//下面设置可以下载apk和nupkg类型的文件
ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
{
{ ".apk", "application/vnd.android.package-archive" }
})
});
2 years ago
// 先开启认证
app.UseAuthentication();
// 然后是授权中间件
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
2 years ago
app.Run();