当前位置: 首页>>代码示例>>C#>>正文


C# IServiceCollection.ConfigureSwaggerGen方法代码示例

本文整理汇总了C#中IServiceCollection.ConfigureSwaggerGen方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.ConfigureSwaggerGen方法的具体用法?C# IServiceCollection.ConfigureSwaggerGen怎么用?C# IServiceCollection.ConfigureSwaggerGen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceCollection的用法示例。


在下文中一共展示了IServiceCollection.ConfigureSwaggerGen方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc()
                .AddJsonOptions(
                    opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); });
            
            services.AddSwaggerGen();
            
            services.ConfigureSwaggerGen(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "IO.Swagger",
                    Description = "IO.Swagger (ASP.NET Core 1.0)"
                });

                options.DescribeAllEnumsAsStrings();

                var comments = new XPathDocument($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml");
                options.OperationFilter<XmlCommentsOperationFilter>(comments);
                options.ModelFilter<XmlCommentsModelFilter>(comments);
            });
            
        }
开发者ID:expectedbehavior,项目名称:swagger-codegen,代码行数:27,代码来源:Startup.cs

示例2: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            services.AddLogging();

            // Add our repository type.
            services.AddSingleton<ITodoRepository, TodoRepository>();

            // Inject an implementation of ISwaggerProvider with defaulted settings applied.
            services.AddSwaggerGen();

            // Add the detail information for the API.
            services.ConfigureSwaggerGen(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "ToDo API",
                    Description = "A simple example ASP.NET Core Web API",
                    TermsOfService = "None",
                    Contact = new Contact { Name = "Shayne Boyer", Email = "", Url = "http://twitter.com/spboyer"},
                    License = new License { Name = "Use under LICX", Url = "http://url.com" }
                });

                //Determine base path for the application.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;

                //Set the comments path for the swagger json and ui.
                options.IncludeXmlComments(basePath + "\\TodoApi.xml");
            });
        }
开发者ID:MaherJendoubi,项目名称:Docs,代码行数:34,代码来源:Startup.cs

示例3: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddMvc()
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                });

            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();

            services.AddSwaggerGen(c =>
            {
                c.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "Swashbuckle Sample API",
                    Description = "A sample API for testing Swashbuckle",
                    TermsOfService = "Some terms ..."
                });

                c.DescribeAllEnumsAsStrings();

                c.OperationFilter<AssignOperationVendorExtensions>();
            });

            if (_hostingEnv.IsDevelopment())
            {
                services.ConfigureSwaggerGen(c =>
                {
                    c.IncludeXmlComments(string.Format(@"{0}\artifacts\bin\Basic\{1}\{2}{3}\Basic.xml",
                        GetSolutionBasePath(),
                        _appEnv.Configuration,
                        _appEnv.RuntimeFramework.Identifier,
                        _appEnv.RuntimeFramework.Version.ToString().Replace(".", string.Empty)));
                });
            }
        }
开发者ID:andycmaj,项目名称:Ahoy,代码行数:42,代码来源:Startup.cs

示例4: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.     
            services.AddMvc().AddXmlSerializerFormatters();

            IBookChaptersRepository repos = new SampleBookChaptersRepository();
            repos.Init();
            services.AddSingleton(repos);

            services.AddSwaggerGen();           

            services.ConfigureSwaggerGen(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "Book Chapters",
                    Description = "A sample for Professional C# 6"
                });
                options.IgnoreObsoleteActions();
                options.IgnoreObsoleteProperties();
                options.DescribeAllEnumsAsStrings();
            });
        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:25,代码来源:Startup.cs

示例5: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddInstance<IHostingEnvironment>(_hostingEnvironment);
            services.AddInstance<IApplicationEnvironment>(_appEnvironment);
            services.AddOptions();

            services.AddAuthentication();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("Authenticated", policy => policy.RequireAuthenticatedUser());
            });

            services.AddElm();
            services.ConfigureElm(options =>
            {
//                options.Path = new PathString("/foo");  // defaults to "/Elm"
                options.Filter = (name, level) => level >= LogLevel.Information;
            });

            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            });
            services.AddMvcCore().AddJsonFormatters();
            services.AddSwaggerGen(c =>
            {
                c.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "Swashbuckle Sample API",
                    Description = "A sample API for testing Swashbuckle",
                    TermsOfService = "Some terms ..."
                });

                c.DescribeAllEnumsAsStrings();

                c.OperationFilter<AssignOperationVendorExtensions>();
             
            });

            if (_hostingEnvironment.IsDevelopment())
            {
                services.ConfigureSwaggerGen(c =>
                {
                    var xmlPath = string.Format(@"{0}\artifacts\bin\WebApplication1\{1}\{2}{3}\WebApplication1.xml",
                        GetSolutionBasePath(),
                        _appEnvironment.Configuration,
                        _appEnvironment.RuntimeFramework.Identifier,
                        _appEnvironment.RuntimeFramework.Version.ToString().Replace(".", string.Empty));
                   
                    c.IncludeXmlComments(xmlPath);

                    var xmlPath2 = string.Format(@"{0}\artifacts\bin\p6.api.animals.v1\{1}\dotnet5.4\p6.api.animals.v1.xml",
                       GetSolutionBasePath(),
                       _appEnvironment.Configuration);

                    c.IncludeXmlComments(xmlPath2);

                });
            }

            services.AddLogging();
            services.AddWebEncoders();
            services.AddCors();

            services.AddCaching(); // Memory Caching stuff
            services.AddSession();

            // register the global configuration root 
            services.AddSingleton<IConfigurationRoot, GlobalConfigurationRoot>();

            services.Configure<CassandraConfig>(Configuration.GetSection(CassandraConfig.WellKnown_SectionName));


            // Add application services.

            // Do this before we do a BuildServiceProvider because some downstream autofac modules need the librarymanager.
            ILibraryManager libraryManager = null;
            libraryManager = services.GetService<ILibraryManager>();
            TypeGlobals.LibraryManager = libraryManager;

            services.AddSingleton<IFilterProvider, Pingo.Core.Providers.OptOutOptInFilterProvider>();

            services.AddTransient<ClaimsPrincipal>(
               s => s.GetService<IHttpContextAccessor>().HttpContext.User);

            services.Configure<IdentityOptions>(options =>
            {
                options.Cookies.ApplicationCookie.LoginPath = new Microsoft.AspNet.Http.PathString("/Identity/Account/Login");
                options.Cookies.ApplicationCookie.LogoutPath = new Microsoft.AspNet.Http.PathString("/Identity/Account/LogOff");
            });

            services.AddAllConfigureServicesRegistrants(Configuration);
            // autofac auto registration
            services.AddDependencies();
            var serviceProvider = services.BuildServiceProvider(Configuration);

            // Setup the PingoGlobal static .  Easier to use that trying to resolve everytime.
//.........这里部分代码省略.........
开发者ID:ghstahl,项目名称:vNext.Jan2016Web,代码行数:101,代码来源:Startup.cs

示例6: ConfigureSwagger

        // Entry point for the application.       

        #region Private Methods

        #region Swagger
        private void ConfigureSwagger(IServiceCollection services)
        {
            string pathToDoc = $"{System.AppDomain.CurrentDomain.BaseDirectory}Microsoft.Legal.MatterCenter.Web.xml";
            services.AddSwaggerGen();
            services.ConfigureSwaggerGen(options => {
                options.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "Matter Center API Version V1",
                    Description = "This matter center api is for V1 release",
                    TermsOfService = "None",
                    Contact = new Contact() {
                        Name="Matter Admin",
                        Email= "[email protected]",
                        Url = "https://www.microsoft.com/en-us/legal/productivity/mattercenter.aspx"
                    }
                });
                options.IncludeXmlComments(pathToDoc);
                options.DescribeAllEnumsAsStrings();
                options.IgnoreObsoleteActions();

            });
            services.ConfigureSwaggerGen(options =>
            {
                options.DescribeAllEnumsAsStrings();
                options.IgnoreObsoleteProperties();

            });
        }
开发者ID:Microsoft,项目名称:mattercenter,代码行数:34,代码来源:Startup.cs

示例7: RegisterSwagger

        private static void RegisterSwagger(IServiceCollection services)
        {
            services.ConfigureSwaggerGen(opt =>
            {
                opt.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "Music Store API",
                    Description = "API for SSW Music Store"
                });

                opt.DescribeAllEnumsAsStrings();
            });

            services.AddSwaggerGen();
        }
开发者ID:SSWConsulting,项目名称:enterprise-musicstore-api-aspnet,代码行数:16,代码来源:Startup.cs

示例8: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Add PostgreSQL support
            services.AddEntityFrameworkNpgsql()
                .AddDbContext<DockerCommandsDbContext>(options =>
                    options.UseNpgsql(Configuration["Data:DbContext:DockerCommandsConnectionString"]))
                .AddDbContext<CustomersDbContext>(options =>
                    options.UseNpgsql(Configuration["Data:DbContext:CustomersConnectionString"]));

            services.AddMvc();

            // Add our PostgreSQL Repositories (scoped to each request)
            services.AddScoped<IDockerCommandsRepository, DockerCommandsRepository>();
            services.AddScoped<ICustomersRepository, CustomersRepository>();

            //Transient: Created each time they're needed
            services.AddTransient<DockerCommandsDbSeeder>();
            services.AddTransient<CustomersDbSeeder>();

            //Nice article by Shayne Boyer here on Swagger:
            //https://docs.asp.net/en/latest/tutorials/web-api-help-pages-using-swagger.html
            services.AddSwaggerGen();
            services.ConfigureSwaggerGen(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "ASP.NET Core Customers API",
                    Description = "ASP.NET Core Customers Web API documentation",
                    TermsOfService = "None",
                    Contact = new Contact { Name = "Dan Wahlin", Url = "http://twitter.com/danwahlin"},
                    License = new License { Name = "MIT", Url = "https://en.wikipedia.org/wiki/MIT_License" }
                });

                //Enable following for XML comment support and add "xmlDoc": true to buildOptions in project.json

                //Base app path
                //var basePath = PlatformServices.Default.Application.ApplicationBasePath;

                //Set the comments path for the swagger json and ui.
                //options.IncludeXmlComments(basePath + "\\yourAPI.xml");

            });
        }
开发者ID:DanWahlin,项目名称:AspNetCorePostgreSQLDockerApp,代码行数:45,代码来源:Startup.cs

示例9: ConfigureSwagger

        private void ConfigureSwagger(IServiceCollection services)
        {
            services.AddSwaggerGen();
            services.ConfigureSwaggerGen(options => {
                options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info
                {
                    Version = "v1",
                    Title = "Matter Center API Version V1",
                    Description = "This matter center api is for V1 release"
                });
                options.IgnoreObsoleteActions();

            });
            services.ConfigureSwaggerGen(options =>
            {
                options.DescribeAllEnumsAsStrings();
                options.IgnoreObsoleteProperties();

            });
        }
开发者ID:Microsoft,项目名称:mattercenter,代码行数:20,代码来源:Startup.cs


注:本文中的IServiceCollection.ConfigureSwaggerGen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。