vs webapi 取消controller

1、添加引用

using Panda.DynamicWebApi;

2、starup.cs

public void ConfigureServices(IServiceCollection services)
{
            //注入HttpContextAccessor
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            //启动缓存
            services.AddMemoryCache();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddMvc(options =>
            {
                options.Filters.Add<HttpGlobalExceptionFilter>();
            });
            //自动生成Api文档
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
                {
                    Version = "v1",
                    Title = "API",
                    Description = "OpenApi文档"
                });
                options.DocInclusionPredicate((docName, description) => true);
                //true表示生成控制器描述,包含true的IncludeXmlComments重载应放在最后,或者两句都使用true
                options.IncludeXmlComments(@"bin\Debug\netcoreapp2.2\OneCode.HongYan.OpenApi.xml");
                options.IncludeXmlComments(@"bin\Debug\netcoreapp2.2\OneCode.HongYan.Application.xml");
            });

            // 添加动态WebApi 需放在 AddMvc 之后
            services.AddDynamicWebApi();
}

 

posted @ 2019-10-17 09:21  韩梦芫  阅读(415)  评论(0编辑  收藏  举报