zyf
8 天以前 91489875fc8c9fd2b44c3791ca6f67dcf559675f
MESApplication/Startup.cs
@@ -1,4 +1,8 @@
using Microsoft.OpenApi.Models;
using System.Reflection;
using MES.Service.Dto.@base;
using MES.Service.util;
using MESApplication.Filter;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Swashbuckle.AspNetCore.SwaggerUI;
@@ -13,6 +17,8 @@
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
        new AppsettingsUtility().Initial(configuration);
    }
    public IConfiguration Configuration { get; }
@@ -21,11 +27,20 @@
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();
        // 读取 系统 设置并注入到服务中
        services.Configure<AppSettings>(
            Configuration.GetSection("AppSettings"));
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1",
                new OpenApiInfo
                    { Title = "MESApplication.Api", Version = "v1" });
            var xmlFile =
                $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
            var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
            c.IncludeXmlComments(xmlPath, true);
        });
        //配置JSON.NET
@@ -57,6 +72,18 @@
                        "OPTIONS")
            );
        });
        #region 接口行动过滤器
        services.AddControllers(options =>
        {
            options.Filters.Add(new ActionFilter());
        });
        var serviceProvider = services.BuildServiceProvider();
        ActionFilter.LoggerError =
            serviceProvider.GetRequiredService<ILogger<ActionFilter>>();
        #endregion
    }
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -83,5 +110,9 @@
        app.UseAuthorization();
        app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
        //////////////////////////
        ///////////////////////////
    }
}