本文整理汇总了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);
});
}
示例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");
});
}
示例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)));
});
}
}
示例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();
});
}
示例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.
//.........这里部分代码省略.........
示例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();
});
}
示例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();
}
示例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");
});
}
示例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();
});
}