using DS.Module.Core;
using DS.Module.Core.Filters;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace DS.WMS.WebApi;
///
/// 基础服务
///
public static class DsAppWebInstall
{
///
/// 将模块服务添加到依赖注入服务容器中
///
/// 依赖注入服务容器
///
public static IServiceCollection AddAppWebInstal(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddControllers(options =>
{
//全局异常过滤
options.Filters.Add();
options.SuppressAsyncSuffixInActionNames = false;
})
.ConfigureApiBehaviorOptions(options =>
{
options.SuppressModelStateInvalidFilter = true;
//使用自定义模型验证
options.InvalidModelStateResponseFactory = (context) =>
{
var errors = context.ModelState
.Where(e => e.Value.Errors.Count > 0)
.Select(e => e.Value.Errors.First().ErrorMessage)
.ToList();
var result = DataResult