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.
87 lines
3.1 KiB
C#
87 lines
3.1 KiB
C#
using DS.WMS.PrintApi.Service;
|
|
using DS.WMS.PrintApi.Utils;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Newtonsoft.Json;
|
|
using System.Text.Encodings.Web;
|
|
using System.Text.Unicode;
|
|
|
|
namespace DS.WMS.PrintApi
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddControllers();
|
|
//注入IWMSCommonService 公共服务
|
|
services.AddSingleton<IOpenPrintService, OpenPrintService>();
|
|
|
|
services.AddControllers(
|
|
(options =>
|
|
{
|
|
// 204预检查过滤
|
|
//options.Filters.Add<FegCrosFilter>();
|
|
//全局异常过滤
|
|
options.Filters.Add<GlobalExceptionsFilter>();
|
|
options.SuppressAsyncSuffixInActionNames = false;
|
|
}))
|
|
.AddNewtonsoftJson(options =>
|
|
{
|
|
//CustomContractResolver 是我们自定义的解析器
|
|
options.SerializerSettings.ContractResolver = new CustomContractResolver();
|
|
|
|
// 时间格式化
|
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|
// 忽略循环引用
|
|
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
|
// 忽略空值
|
|
// options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
|
|
})
|
|
.AddJsonOptions(cfg =>
|
|
{
|
|
//解决后端返回数据中文被编码
|
|
cfg.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
|
|
});
|
|
//Swagger
|
|
services.AddSwaggerSetup();
|
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
var documentName = AppSetting.Configuration["SwaggerDoc:ContactName"];
|
|
// app.UseHttpsRedirection();
|
|
app.UseSwagger().UseSwaggerUI(c =>
|
|
{
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", documentName);
|
|
});
|
|
app.UseRouting();
|
|
//静态文件
|
|
app.UseStaticFiles();
|
|
// 先开启认证
|
|
app.UseAuthentication();
|
|
// 然后是授权中间件
|
|
app.UseAuthorization();
|
|
|
|
//app.UseMiddleware<ApiAuthMiddleware>();
|
|
|
|
|
|
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
|
}
|
|
}
|
|
}
|