本文整理汇总了C#中IServiceCollection.AddOptions方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddOptions方法的具体用法?C# IServiceCollection.AddOptions怎么用?C# IServiceCollection.AddOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ImdbContext>();
services.AddOptions();
services.Configure<ImdbOptions>(_configuration.GetSection("Imdb"));
services.AddMvc();
services.Configure<MvcOptions>(options =>
{
options.OutputFormatters.Clear();
options.InputFormatters.Clear();
var jss = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
jss.Converters.Add(new StringEnumConverter());
options.InputFormatters.Add(new JsonInputFormatter(jss));
options.OutputFormatters.Add(new JsonOutputFormatter(jss));
options.InputFormatters.Add(new XmlSerializerInputFormatter());
options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
});
}
示例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.AddEntityFramework()
.AddSqlServer()
.AddDbContext<SiteContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<SiteContext>()
.AddDefaultTokenProviders();
services.AddOptions();
services.Configure<BraintreeSettings>(Configuration.GetSection("AppSettings:Braintree"));
services.Configure<ConstantContactSettings>(Configuration.GetSection("AppSettings:ConstantContact"));
services.AddMvc();
services.AddCaching();
services.AddSession();
services.ConfigureRouting(opts =>
{
opts.AppendTrailingSlash = false;
opts.LowercaseUrls = true;
});
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddScoped<IBookstoreRepository, EFBookstoreRepository>();
}
示例4: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
services.AddOptions();
services.Configure<ConfigOptions>(Configuration);
services.AddMvc();
}
示例5: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<ServiceSettingsModel>(Configuration);
// Add framework services.
services.AddMvc();
}
示例6: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMultitenancy<AppTenant, CachingAppTenantResolver>();
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddOptions();
services.AddMvc();
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new TenantViewLocationExpander());
});
services.Configure<MultitenancyOptions>(Configuration.GetSection("Multitenancy"));
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
示例7: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<MessageConfiguration>(Configuration);
services.AddLogging();
services.AddScoped<ISecretNumber>(provider => new SecretNumber(Configuration));
}
示例8: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.AddSingleton<IConfigurationRoot>(Configuration);
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddAuthentication(Configuration);
services.Configure<PayPalClientSettings>(Configuration.GetSection("PayPalClientSettings"));
services.AddSingleton<PayPalClient>();
services.AddLogging();
services.AddMvc();
// register document store
var store = DocumentStore.For(_ =>
{
_.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate;
_.Connection(Configuration.GetConnectionString("HopeNB"));
AsyncSessionFactory.Register(_);
});
store.Schema.ApplyAllConfiguredChangesToDatabase();
services.AddSingleton<IDocumentStore>(store);
AsyncSessionFactory.DocumentStore = store;
services.AddDistributedMemoryCache();
services.AddMultitenancy<Organization, CachingOrganizationResolver>();
}
示例9: 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();
}
示例10: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var useInMemoryStore = !_Platform.IsRunningOnWindows || _Platform.IsRunningOnMono || _Platform.IsRunningOnNanoServer;
services.ConfigureDataContext(Configuration, useInMemoryStore);
// Register dependencies
services.ConfigureDependencies(Configuration);
// Add Entity Framework services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MyHealthContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// Add MVC services to the services container.
services.AddMvc();
services.AddOptions();
services.Configure<DefaultUser>(Configuration.GetSection("DefaultUser"));
services.Configure<Office365Options>(Configuration.GetSection("Data:Office365"));
services.AddSingleton<IMemoryCache, MemoryCache>();
// 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();
}
示例11: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddHosting();
services.AddOptions();
services.AddLogging();
services.AddMvc();
// configuring services
// force JSON
// remove XML
services.Configure<Microsoft.AspNet.Mvc.MvcOptions>
(
options
=>
options
.OutputFormatters
.RemoveAll
(
formatter
=>
formatter.Instance
is
Microsoft.AspNet.Mvc.XmlDataContractSerializerOutputFormatter
)
);
return;
}
示例12: 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;
});
}
示例13: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<ConfigServerDataAsOptions>(Configuration);
services.AddMvc();
}
示例14: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<MySettings>(_configuration);
services.Configure<OtherSettings>(_configuration.GetSection("otherSettings"));
services.AddScoped<MyClass>();
}
示例15: 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.AddOptions();
services.AddCloudFoundry(Configuration);
}