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


C# IServiceCollection.AddSwaggerGen方法代码示例

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


在下文中一共展示了IServiceCollection.AddSwaggerGen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.AddApplicationInsightsTelemetry(Configuration);

            services.AddAuthorization();

            services.AddOptions();

            services.Configure<ConnectionOptions>(Configuration);

            services.AddMvc(config =>
            {
                var policy = new AuthorizationPolicyBuilder()
                                 .RequireAuthenticatedUser()
                                 .Build();
                config.Filters.Add(new AuthorizeFilter(policy));
            });

            services.AddCors();

            services.AddSwaggerGen();

            services.AddRepositoryRegistrations();
        }
开发者ID:MightyDevelopers,项目名称:solutions,代码行数:26,代码来源:Startup.cs

示例2: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            // Configure swagger. For more details see e.g.
            // http://damienbod.com/2015/12/13/asp-net-5-mvc-6-api-documentation-using-swagger/
            services.AddSwaggerGen();
            services.ConfigureSwaggerDocument(options => options.SingleApiVersion(
                new Info { Version = "v1", Title = "Demo" }));

            // Use the new configuration model here. Note the use of 
            // different configuration sources (json, env. variables,
            // middleware-specific configuration).
            services.AddOptions();
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .AddEnvironmentVariables()
                .AddApplicationInsightsSettings(developerMode: true);
            var configuration = builder.Build();

            // Publish options read from configuration file. With that,
            // controllers can use ASP.NET DI to get options (see 
            // BooksController).
            services.Configure<BooksDemoDataOptions>(
                configuration.GetSection("booksDemoDataOptions"));

            // Add AI configuration
            services.AddApplicationInsightsTelemetry(configuration);

            // Publish singleton for name generator
            services.AddSingleton(typeof(INameGenerator), typeof(NameGenerator));

            // Configure middlewares (CORS and MVC)
            services.AddCors();
            services.AddMvc();
        }
开发者ID:BarfieldMV,项目名称:Samples,代码行数:34,代码来源:Startup.cs

示例3: 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.AddApplicationInsightsTelemetry(Configuration);

            services.AddMvc();
            services.AddSwaggerGen();
            var filePath = Environment.CurrentDirectory.Split(new[] { "src" }, StringSplitOptions.None)[0] + Configuration["Documentation:SwaggerDocXml"];
            services.ConfigureSwaggerDocument(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "Todo API",
                    Description = "A sample api",
                    TermsOfService = "None"
                });
                options.OperationFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlActionComments(filePath));
            });
            services.ConfigureSwaggerSchema(options =>
            {
                options.DescribeAllEnumsAsStrings = true;
                options.ModelFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlTypeComments(filePath));
            });
            services.AddSingleton<ITodoRepository, TodoRepository>();
        }
开发者ID:disha-s,项目名称:SampleApplicationsInASP.NET5,代码行数:27,代码来源: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()
                .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

示例5: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddCaching();
            services.AddSession();

            services.AddSwaggerGen();

            services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure<MvcOptions>(options =>
            {
                //options.RespectBrowserAcceptHeader = true;
            });
            services.AddEntityFramework()
                .AddInMemoryDatabase()
                .AddDbContext<ApplicationDbContext>(options => { options.UseInMemoryDatabase(); });

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddUserStore<ApplicationUserStore<ApplicationUser>>()
                .AddDefaultTokenProviders();

            services.AddTransient<ApplicationUserManager>();
            services.AddTransient<ApplicationSignInManager>();
            services.AddTransient<IUserImageProvider, GravatarProvider>();

            services.AddAuthentication();

            // https://github.com/aspnet/Entropy/blob/dev/samples/Logging.Elm/Startup.cs
            services.AddElm();
        }
开发者ID:CWISoftware,项目名称:accounts,代码行数:32,代码来源:Startup.cs

示例6: 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.AddLogging();
     services.AddMvc();
     services.AddSwaggerGen();
 }
开发者ID:jjcollinge,项目名称:blanky,代码行数:8,代码来源:Startup.cs

示例7: 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

示例8: 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.AddApplicationInsightsTelemetry(Configuration);

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["ConnectionString"]));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();


            services.AddMvc();

            //Swagger additons
            services.AddMvcCore()
                .AddApiExplorer();

            services.AddSwaggerGen();
            
            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<BookServiceContext>(options =>
                options.UseSqlServer(Configuration["ConnectionString"]));
            //options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=BookServiceContext-70e8c6ed-94f8-4d84-97df-d0729ea62482;Trusted_Connection=True;MultipleActiveResultSets=true"));
        }
开发者ID:jlrc,项目名称:BookService-Core,代码行数:34,代码来源:Startup.cs

示例9: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            // 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();
        }
开发者ID:andycmaj,项目名称:Ahoy,代码行数:11,代码来源:Startup.cs

示例10: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AuthSettings>(Configuration.GetSection("Auth"));

            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

            /*
            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();
                */

            services.AddMvc();

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();
            services.AddTransient<IUserIdentityService, UserIdentityService>();

            var mapperConfig = new MapperConfiguration(cfg =>{});
            services.AddSingleton<IMapper>(provider => mapperConfig.CreateMapper());

            // swagger         
            services.AddSwaggerGen();

            services.ConfigureSwaggerDocument(options =>
            {
                options.MultipleApiVersions(new Info[]
                {
                    new Swashbuckle.SwaggerGen.Info
                    {
                        Version = "v1",
                        Title = "Dite API",
                        Description = "Dite RESTful API"
                    },
                    new Swashbuckle.SwaggerGen.Info
                    {
                        Version = "v2",
                        Title = "Dite API (v2)",
                        Description = "Dite RESTful API"
                    }
                }, VersionSupportResolver);               
                //options.OperationFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlActionComments(pathToDoc));
            });

            services.ConfigureSwaggerSchema(options =>
            {
                options.DescribeAllEnumsAsStrings = true;
                //options.ModelFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlTypeComments(pathToDoc));
            });
        }
开发者ID:tinodu,项目名称:Dite,代码行数:58,代码来源:Startup.cs

示例11: ConfigureServices

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

            services.AddSwaggerGen();

            services.AddSingleton<ITodoItemRepository, TodoItemRepository>(provider => new TodoItemRepository(Configuration["mongoconnection"], Configuration["database"]) );
        }
开发者ID:CedricLeblond,项目名称:MultiChannelTodo,代码行数:11,代码来源:Startup.cs

示例12: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AppSettings>(opt => Configuration.GetSection("AppSettings"));

            services.AddMvc()
                .AddVersionEndpoint();

            services.AddBusinessServices();
            services.AddAutoMapper();
            services.AddSwaggerGen();
        }
开发者ID:digipolisantwerp,项目名称:generator-dgp-web-aspnetcore_yeoman,代码行数:11,代码来源:Startup.cs

示例13: 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.AddSingleton<IBooksService, BooksService>();
     services.AddDbContext<BooksContext>(options =>
     {
         options.UseSqlServer(Configuration.GetConnectionString("BooksConnection"));
     });
     services.AddSwaggerGen();
 }
开发者ID:CNinnovation,项目名称:WindowsApps,代码行数:12,代码来源:Startup.cs

示例14: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvcCore()
                    .AddApiExplorer()
                    .AddJsonFormatters();

            services.AddEntityFramework()
                    .AddInMemoryDatabase()
                    .AddDbContext<VotingContext>(options =>
                            options.UseInMemoryDatabase());

            services.AddSwaggerGen();
        }
开发者ID:paulopez78,项目名称:voting,代码行数:13,代码来源:StartUp.cs

示例15: AddSwagger

 private static void AddSwagger(IServiceCollection services)
 {
     services.AddSwaggerGen();
     services.ConfigureSwaggerDocument(options =>
     {
         options.SingleApiVersion(new Info
         {
             Version = "v1",
             Title = "Artist Lookup Service",
             Description = "A simple mashup service for artist details lookup using a MusicBrainz ID",
             TermsOfService = "None"
         });
     });
 }
开发者ID:MarcusParkkinen,项目名称:artist-lookup-service,代码行数:14,代码来源:Startup.cs


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