• .Net Core之Swagger


    1.项目生成xml

    2.添加链接文件,并将属性设值为始终复制

    3.添加swagger引用:Swashbuckle.AspNetCore

    4.startup.cs配置swargger的xml来源:

    ConfigureServices方法添加:

                services.AddMvc();
                services.AddOptions();
                services.AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("v1", new Info { Title = "DVM AdsPlatformProxy Service WebApi", Version = "v1.0.0.3" });
                    var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                    var docPath = Path.Combine(basePath, "Docs");
                    var docs = XMLUtil.CreateXPathDocumentsFromDirectory(docPath);
                    docs.ForEach(xp => c.IncludeXmlComments(() => { return xp; }));
                });//swagger文件路径配置
                services.RegisterServiceR<ILogBase, NLogger>(IocLifeStyle.Singleton);
                services.RegisterServiceR<IAppNexusProxy, AppNexusProxyService>(IocLifeStyle.Scoped);
                services.RegisterServiceR<ICriteoProxy, CriteoProxyService>(IocLifeStyle.Scoped);
                services.RegisterServiceR<ITaboolaProxy,TaboolaProxyService>(IocLifeStyle.Scoped);
                services.RegisterServiceR<IBrightRollProxy,BrightRollProxyService>(IocLifeStyle.Scoped);
                services.RegisterServiceR<IFaceBookProxyService, FacebookProxyService>(IocLifeStyle.Scoped);
    

      

    Configure方法添加

                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    app.UseBrowserLink();
                }
                else
                {
                    app.UseExceptionHandler("/Error");
                }
    
                app.UseSwagger();
    
                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "DVM AdsPlatformProxy Service WebApi V1");
                });//swagger ui
    
    
                app.UseStaticFiles();
    
                app.UseMvc();
    

      

  • 相关阅读:
    RHEL 6.5 安装Docker
    sar命令
    Linux 安装部署 Redis
    hugepage设置
    pycharm使用
    oracle如何保证数据一致性和避免脏读
    转:数据库实例自动crash并报ORA-27157、ORA-27300等错误
    oracle安装内核参数设置
    外部表
    LNMP环境搭建
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/8341852.html
Copyright © 2020-2023  润新知