本文整理汇总了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();
}
示例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();
}
示例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>();
}
示例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);
});
}
示例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();
}
示例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();
}
示例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");
});
}
示例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"));
}
示例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();
}
示例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));
});
}
示例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"]) );
}
示例12: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(opt => Configuration.GetSection("AppSettings"));
services.AddMvc()
.AddVersionEndpoint();
services.AddBusinessServices();
services.AddAutoMapper();
services.AddSwaggerGen();
}
示例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();
}
示例14: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddApiExplorer()
.AddJsonFormatters();
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<VotingContext>(options =>
options.UseInMemoryDatabase());
services.AddSwaggerGen();
}
示例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"
});
});
}