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


C# IServiceCollection.AddOptions方法代码示例

本文整理汇总了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();
        }
开发者ID:BarfieldMV,项目名称:Samples,代码行数:34,代码来源:Startup.cs

示例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());
			});
		}
开发者ID:ProgramUtvikling,项目名称:mvckurs-jan-2016,代码行数:31,代码来源: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.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>();
        }
开发者ID:malevolence,项目名称:ContosoBooks,代码行数:33,代码来源:Startup.cs

示例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();
 }
开发者ID:Chips100,项目名称:Dennika.WebApplication,代码行数:8,代码来源:Startup.cs

示例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();
 }
开发者ID:danvy,项目名称:sigfox,代码行数:8,代码来源: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)
        {
            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>();
        }
开发者ID:3arlN3t,项目名称:saaskit,代码行数:30,代码来源:Startup.cs

示例7: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddOptions();
     services.Configure<MessageConfiguration>(Configuration);
     services.AddLogging();
     services.AddScoped<ISecretNumber>(provider => new SecretNumber(Configuration));
 }
开发者ID:Mtahtaci,项目名称:aspnet5samples,代码行数:7,代码来源:Startup.cs

示例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>();
        }
开发者ID:HopeNB,项目名称:web,代码行数:32,代码来源:Startup.cs

示例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();
        }
开发者ID:MightyDevelopers,项目名称:solutions,代码行数:26,代码来源: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)
        {
            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();          
        }
开发者ID:geekpivot,项目名称:HealthClinic.biz,代码行数:28,代码来源:Startup.cs

示例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;
		}
开发者ID:moljac,项目名称:Ph4ct3x,代码行数:29,代码来源:Startup.cs

示例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;
            });
        }
开发者ID:BartDeVries,项目名称:RESTGateway,代码行数:28,代码来源:Startup.cs

示例13: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure<ConfigServerDataAsOptions>(Configuration);

            services.AddMvc();
        }
开发者ID:chrisumbel,项目名称:Configuration,代码行数:7,代码来源:TestServerStartup.cs

示例14: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure<MySettings>(_configuration);
            services.Configure<OtherSettings>(_configuration.GetSection("otherSettings"));

            services.AddScoped<MyClass>();
        }
开发者ID:jeffogata,项目名称:aspnet-configuration-04-cli,代码行数:8,代码来源:Startup.cs

示例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);        
        }
开发者ID:chrisumbel,项目名称:core,代码行数:9,代码来源:Startup.cs


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