.net API 本地和IIS 上面添加说明文档

using log4net;
using log4net.Config;
using log4net.Repository;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Swashbuckle;
using Microsoft.AspNetCore.Routing;
using System.Reflection;

namespace Kema_Middleware_Api
{
    public class Startup
    {

        public static ILoggerRepository Repository = null;
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            Repository = LogManager.CreateRepository("NETCoreRepository");
            XmlConfigurator.Configure(Repository, new FileInfo("log4net.config"));
        }
        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)
        {

            //注册Swagger生成器,定义一个和多个Swagger 文档

            services.AddSwaggerGen(c =>
            {
                Microsoft.OpenApi.Models.OpenApiInfo info = new Microsoft.OpenApi.Models.OpenApiInfo();
                info.Title = "柴油机中间件API V1";
                info.Version = "v1";
                c.SwaggerDoc("v1", info);
                //自动生成Api文档
                c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());

                //将SwaggerUI 添加中文注释提示
                //将application 层中的注释添加到SwaggerUI中,这样就会有中文提示,比较友好
                string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
                string xmlPath = "Kema_Middleware_Api.xml";
                string commentsFile = Path.Combine(baseDirectory, xmlPath);
                c.IncludeXmlComments(commentsFile);

            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
            // Enable static files middleware.
            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();

            //启用中间件服务生成Swagger作为JSON终结点
            app.UseSwagger();
            app.UseSwagger(c =>
            {
                //添加这一句才会在iis上显示文档
                c.RouteTemplate = "swagger/{documentname}/swagger.json";
            });
            //启用中间件服务对swagger-ui,指定Swagger JSON终结点
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "柴油机中间件API V1");
                c.RoutePrefix = string.Empty;

            });

          
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值