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


C# IServiceCollection.AddSwagger方法代码示例

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


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

示例1: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<IDataStore<Project>, CommonDataStore<Project>>();
            services.AddTransient<IDataStore<Project, Sprint>, CommonDataStore<Project, Sprint>>();
            services.AddTransient<IDataStore<Project, Sprint, Issue>, CommonDataStore<Project, Sprint, Issue>>();
            services.AddTransient<IDataStore<Project, Sprint, Issue, Comment>, CommonDataStore<Project, Sprint, Issue, Comment>>();
            services.AddTransient<IDataStore<Project, Sprint, Issue, Attachment>, CommonDataStore<Project, Sprint, Issue, Attachment>>();

            services.AddTransient<IDataStore<User>, CommonDataStore<User>>();
            services.AddTransient<IDataStore<UserGroup>, CommonDataStore<UserGroup>>();

            services.AddTransient<ProjectsController>();
            services.AddTransient<SprintsController>();
            services.AddTransient<IssuesController>();
            services.AddTransient<CommentsController>();
            services.AddTransient<AttachmentsController>();
            services.AddTransient<UsersController>();

            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.AddSwagger();
        }
开发者ID:aguldstrand,项目名称:Tasky,代码行数:27,代码来源:Startup.cs

示例2: ConfigureServices

        /// <summary>
        /// This method gets called by a runtime.
        /// Use this method to add services to the container 
        /// </summary>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(c =>
            {
                var jsonFormatter = c.OutputFormatters.OfType<JsonOutputFormatter>().First();
                jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                jsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
                jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
            });

            // 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.AddSwagger();
            services.ConfigureSwaggerDocument(c =>
            {
                c.SingleApiVersion(new Info { Version = "v1", Title = "GreenvilleWiApi" });
                c.OperationFilter<GreenvilleApiFilter>();
                c.OperationFilter<ApplySwaggerOperationFilterAttributes>();
                c.DocumentFilter<GreenvilleApiFilter>();
                c.IgnoreObsoleteActions = true;
            });

            services.ConfigureSwaggerSchema(c =>
            {
                c.DescribeAllEnumsAsStrings = true;
                c.ModelFilter<GreenvilleApiFilter>();
            });
        }
开发者ID:dhmncivichacks,项目名称:greenville-wi-api,代码行数: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.AddOptions();

            services.Configure<AppSettings>(Configuration);

            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.AddSwagger();
            services.ConfigureSwaggerDocument(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "Gateway API",
                    Description = "The documentation for the Gateway API"
                });
            });
            services.ConfigureSwaggerSchema(options =>
            {
                options.DescribeAllEnumsAsStrings = true;
            });
        }
开发者ID:BartDeVries,项目名称:RESTGateway,代码行数:28,代码来源:Startup.cs

示例4: 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.AddSwagger();
            services.ConfigureSwaggerDocument(options =>
            {
                options.SecurityDefinitions.Add("oauth2", new OAuth2Scheme
                {
                    Type = "oauth2",
                    Flow = "implicit",
                    AuthorizationUrl = "http://petstore.swagger.io/api/oauth/dialog",
                    Scopes = new Dictionary<string, string>
                        {
                            { "read", "read access" },
                            { "write", "write access" }
                        }
                });

                options.OperationFilter<AssignSecurityRequirements>();
            });
        }
开发者ID:mcliment,项目名称:Ahoy,代码行数:27,代码来源:Startup.cs

示例5: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            // add Entity Framework
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<MoviesAppContext>(options =>
                    options.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=MoviesDatabase;Trusted_Connection=True;MultipleActiveResultSets=true"));

            // add ASP.NET Identity
            services.AddIdentity<ApplicationUser, IdentityRole>() //Configuration)
                .AddEntityFrameworkStores<MoviesAppContext>()
                .AddDefaultTokenProviders();


            // add ASP.NET MVC
            services.AddMvc();

            services.AddSwagger();
            services.ConfigureSwaggerDocument(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version = "v2",
                    Title = "Swashbuckle Sample API",
                    Description = "A sample API for testing Swashbuckle",
                    TermsOfService = "Some terms ..."
                });

                options.OperationFilter<AssignOperationVendorExtensions>();
            });
            services.ConfigureSwaggerSchema(options =>
            {
                options.DescribeAllEnumsAsStrings = true;
            });
        }
开发者ID:DvdChavarri,项目名称:MovieAngularJSApp,代码行数:35,代码来源:Startup.cs

示例6: 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.AddSwagger();
            services.ConfigureSwaggerDocument(options =>
            {
                options.SingleApiVersion(new Info
                    {
                        Version = "v1",
                        Title = "Swashbuckle Sample API",
                        Description = "A sample API for testing Swashbuckle",
                        TermsOfService = "Some terms ..."
                    });

                options.OperationFilter<AssignOperationVendorExtensions>();
            });
            services.ConfigureSwaggerSchema(options =>
            {
                options.DescribeAllEnumsAsStrings = true;
            });
        }
开发者ID:aytacozkan,项目名称:Ahoy,代码行数:27,代码来源:Startup.cs

示例7: ConfigureServices

        //
        // This method gets called by a runtime.
        // Use this method to add services to the container
        //
        public virtual void ConfigureServices(IServiceCollection services)
        {
#if ENABLE_SWAGGER
            services.AddSwagger();
#endif

            services.AddMvc();
            services.AddSingleton(_ => this.Configuration);

            services.AddLogging();
        }
开发者ID:candela-software,项目名称:appveyor-deployment,代码行数:15,代码来源:StartupBase.cs

示例8: ConfigureSwagger

        /// <summary>
        /// Configures swagger. See https://github.com/domaindrivendev/Swashbuckle
        /// </summary>
        /// <param name="services">The services collection or IoC container.</param>
        /// <param name="configuration">Gets or sets the application configuration, where key value pair settings are 
        /// stored.</param>
        private static void ConfigureSwagger(IServiceCollection services, IConfiguration configuration)
        {
            var configurationSection = configuration.GetSection(nameof(AppSettings));
            AppSettings appSettings = new AppSettings();
            ConfigurationBinder.Bind(configurationSection, appSettings);

            services.AddSwagger(
                x =>
                {
                    // Use strings instead of integers to describe enumerations by default.
                    x.SchemaGeneratorOptions.DescribeAllEnumsAsStrings = true;

                    // If schemes are not explicitly provided in a Swagger 2.0 document, then the scheme used to access
                    // the docs is taken as the default. If your API supports multiple schemes and you want to be 
                    // explicit about them, you can use the "Schemes" option as shown below.
                    x.SwaggerGeneratorOptions.Schemes =
                        new string[]
                        {
                            "http",
                            "https"
                        };

                    // Use "SingleApiVersion" to describe a single version API. Swagger 2.0 includes an "Info" object 
                    // to hold additional metadata for an API.
                    x.SwaggerGeneratorOptions.SingleApiVersion(
                        new Info()
                        {
                            Version = "v1",
                            Title = appSettings.SiteTitle,
                            Description = appSettings.SiteDescription,
                            TermsOfService = appSettings.SiteTermsOfService,
                            Contact = new Swashbuckle.Swagger.Contact()
                            {
                                Name = appSettings.Contact.Name,
                                Email= appSettings.Contact.Email,
                                Url = appSettings.Contact.Url
                            },
                            License = new Swashbuckle.Swagger.License()
                            {
                                Name = appSettings.License.Name,
                                Url = appSettings.License.Url,
                            }
                        });

                    // If your API has multiple versions, use "MultipleApiVersions" instead of "SingleApiVersion".
                    // In this case, you must provide a collection of Info objects for each version of your API and
                    // a lambda that tells Swashbuckle which actions should be included in the docs for a given API 
                    // version.
                    // x.SwaggerGeneratorOptions.MultipleApiVersions(
                    //     GetApiVersions,
                    //     (apiDesc, targetApiVersion) => ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion));
                });
        }
开发者ID:modulexcite,项目名称:ASP.NET-MVC-Boilerplate,代码行数:59,代码来源:Startup.Swagger.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.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
            services.AddMvc();

            services.AddCors();

            services.AddSwagger();

            services.ConfigureSwaggerSchema(o =>
            {
                o.DescribeAllEnumsAsStrings = true;
            });

            services.ConfigureSwaggerDocument(o =>
            {
                o.SingleApiVersion(new Info
                {
                    Version = "v1",
                    Title = "Film Industry Network API",
                    Description = "Documentation of the API for interfacing with the Film Industry Network",
                    TermsOfService = "Use at your own risk"
                });
            });

            services.AddRouting();

            services.AddSingleton<IContext, NetworkContext>();
            services.AddScoped<IPersonRepository, PersonRepository>();
            services.AddScoped<IMovieRepository, MovieRepository>();
            services.AddScoped<IPersonService, PersonService>();
            services.AddScoped<IMovieService, MovieService>();
            services.AddScoped<IGraphMovieService, GraphMovieService>();
            services.AddScoped<IGraphPersonService, GraphPersonService>();
            services.AddTransient<IDataCollectorFactory, DataCollectorFactory>();

            services.Configure<MvcOptions>(options =>
            {
                var settings = new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.Auto
                };
                var jsonFormatter = options.OutputFormatters.Single(o => o.GetType() == typeof(JsonOutputFormatter));
                options.OutputFormatters.Remove(jsonFormatter);
                var outputFormatter = new JsonOutputFormatter { SerializerSettings = settings };
                options.OutputFormatters.Add(outputFormatter);
            });

            //services.AddWebApiConventions();
        }
开发者ID:ewu-modern-database,项目名称:film-industry-network,代码行数:52,代码来源:Startup.cs

示例10: 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.AddSwagger(s => {
                s.SwaggerGeneratorOptions.Schemes = new[] { "http", "https" };
                s.SwaggerGeneratorOptions.SingleApiVersion(new Info {
                    Version = "v1",
                    Title = "WebAPI with NHibernate"
                });
                //s.SwaggerGeneratorOptions.OperationFilter<AssignOperationVendorExtensions>();
                s.SchemaGeneratorOptions.DescribeAllEnumsAsStrings = true;
            });
        }
开发者ID:patkec,项目名称:NHApi,代码行数:19,代码来源:Startup.cs

示例11: ConfigureServices

 // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddCors();
     services.ConfigureCors(options =>
                             options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
                                                                 .AllowAnyMethod()
                                                                 .AllowAnyHeader()));
     services.AddMvc();
     services.AddSwagger(c =>
     {
         c.SwaggerGeneratorOptions.SingleApiVersion(new Info
         {
             Version = "v1",
             Title = "Huzzah!",
             Description = "An example ASP.NET 5 service",
             TermsOfService = "Unintelligible legalese..."
         });
     });
 }
开发者ID:rzachariah,项目名称:hello-aspnet5,代码行数:20,代码来源:Startup.cs

示例12: ConfigureServices

        public static void ConfigureServices(IServiceCollection services)
        {
            services.AddSwagger(
                config =>
                {
                    config.SwaggerGeneratorOptions.SingleApiVersion(
                        new Info
                        {
                            Version = "v1",
                            Title = "ApiAppAspNet5"
                        });

                    config.SwaggerGeneratorOptions.BasePath = "/";

                    config.SwaggerGeneratorOptions.Schemes = new[] { "https" };

                    config.SwaggerGeneratorOptions.OperationFilter<IncludeParameterNamesOperationFilter>();
                });
        }
开发者ID:aetos382,项目名称:ApiAppAspNet5,代码行数:19,代码来源:SwaggerConfig.cs

示例13: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var appEnv = CallContextServiceLocator.Locator.ServiceProvider.GetRequiredService<IApplicationEnvironment>();
            var databaseName = "database.sqlite3";
            var connection = $"Data Source={ appEnv.ApplicationBasePath}/{databaseName}";

            services
                .AddEntityFramework()
                .AddSqlite()

                .AddDbContext<WestWindContext>(options => options.UseSqlite(connection));
            services //no idea want this line can't be added to previous ??
                .AddMvc()
                .AddJsonOptions(options =>
            {
                //elegant handling of circular references
                options.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All;
            });
            services.AddSwagger();
        }
开发者ID:okusnadi,项目名称:AspNet5-Web-Api-Sample,代码行数:20,代码来源:Startup.cs

示例14: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var appEnv = CallContextServiceLocator.Locator.ServiceProvider.GetRequiredService<IApplicationEnvironment>();

            // using inmemory database
            services
                .AddEntityFramework()
                .AddInMemoryDatabase()
                .AddDbContext<TaskContext>(options => options.UseInMemoryDatabase(true));

            services
                .AddMvc()
                .AddJsonOptions(options =>
            {
                //handling of circular references
                options.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All;
            });

            // reading settings from json config
            var configBuilder = new Microsoft.Framework.Configuration.ConfigurationBuilder(appEnv.ApplicationBasePath, null);
            configBuilder.Add(new Microsoft.Framework.Configuration.Json.JsonConfigurationSource(appEnv.ApplicationBasePath + "//appsettings.json"));
            var appsettings = configBuilder.Build();

            // swagger configuration
            string path = string.Format(@"{0}\WebApiSwagger.XML", appEnv.ApplicationBasePath);
            services.AddSwagger(s =>
            {
                s.SwaggerGeneratorOptions.Schemes = new[] { "http", "https" };
                s.SwaggerGeneratorOptions.SingleApiVersion(new Info
                {
                    Version = appsettings["Swagger:Version"],
                    Title = appsettings["Swagger:Title"],
                    Description = appsettings["Swagger:Description"],
                });
                s.IncludeXmlComments(path);
                s.SchemaGeneratorOptions.DescribeAllEnumsAsStrings = true;
                s.SchemaGeneratorOptions.ModelFilters.Add(new ApplyXmlTypeComments(path));
                s.SwaggerGeneratorOptions.OperationFilters.Add(new ApplyXmlActionComments(path));
                s.SwaggerGeneratorOptions.BasePath = appsettings["Swagger:BaseURL"];
            });
        }
开发者ID:lavbox,项目名称:TaskAPI.AspNet5,代码行数:41,代码来源:Startup.cs

示例15: 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.AddSwagger();
            services.ConfigureSwaggerDocument(options =>
            {
                options.MultipleApiVersions(
                    new[]
                    {
                        new Info { Version = "v1", Title = "API V1" },
                        new Info { Version = "v2", Title = "API V2" }
                    },
                    ResolveVersionSupportByVersionsConstraint
                );

                options.DocumentFilter<SetVersionInPaths>();
            });
        }
开发者ID:kjartanvalur,项目名称:Ahoy,代码行数:24,代码来源:Startup.cs


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