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


C# ServiceCollection.Configure方法代码示例

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


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

示例1: ConfigureConfigServerClientSettingsOptions_WithDefaults

        public void ConfigureConfigServerClientSettingsOptions_WithDefaults()
        {
            // Arrange
            var services = new ServiceCollection().AddOptions();
            var environment = new HostingEnvironment();

            // Act and Assert
            var builder = new ConfigurationBuilder().AddConfigServer(environment);
            var config = builder.Build();

            services.Configure<ConfigServerClientSettingsOptions>(config);
            var service = services.BuildServiceProvider().GetService<IOptions<ConfigServerClientSettingsOptions>>();
            Assert.NotNull(service);
            var options = service.Value;
            Assert.NotNull(options);
            ConfigServerTestHelpers.VerifyDefaults(options.Settings);

            Assert.Equal(ConfigServerClientSettings.DEFAULT_PROVIDER_ENABLED, options.Enabled);
            Assert.Equal(ConfigServerClientSettings.DEFAULT_FAILFAST, options.FailFast);
            Assert.Equal(ConfigServerClientSettings.DEFAULT_URI, options.Uri);
            Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, options.Environment);
            Assert.Equal(ConfigServerClientSettings.DEFAULT_CERTIFICATE_VALIDATION, options.ValidateCertificates);
            Assert.Null(options.Name);
            Assert.Null(options.Label);
            Assert.Null(options.Username);
            Assert.Null(options.Password);
        }
开发者ID:sdougherty,项目名称:Configuration,代码行数:27,代码来源:ConfigServerClientSettingsOptionsTest.cs

示例2: ConfigureCloudFoundryOptions_With_VCAP_APPLICATION_Environment_NotPresent

        public void ConfigureCloudFoundryOptions_With_VCAP_APPLICATION_Environment_NotPresent()
        {
            // Arrange
            Environment.SetEnvironmentVariable("VCAP_APPLICATION", null);
            var services = new ServiceCollection().AddOptions();
            // Act and Assert

            var builder = new ConfigurationBuilder().AddCloudFoundry();
            var config = builder.Build();

            services.Configure<CloudFoundryApplicationOptions>(config);
            var service = services.BuildServiceProvider().GetService<IOptions<CloudFoundryApplicationOptions>>();
            Assert.NotNull(service);
            var options = service.Value;

            Assert.Null(options.ApplicationId);
            Assert.Null(options.ApplicationName);
            Assert.Null(options.ApplicationUris);
            Assert.Null(options.ApplicationVersion);
            Assert.Null(options.InstanceId);
            Assert.Null(options.Name);
            Assert.Null(options.SpaceId);
            Assert.Null(options.SpaceName);
            Assert.Null(options.Start);
            Assert.Null(options.Uris);
            Assert.Equal(-1, options.DiskLimit);
            Assert.Equal(-1, options.FileDescriptorLimit);
            Assert.Equal(-1, options.InstanceIndex);
            Assert.Equal(-1, options.MemoryLimit);
            Assert.Equal(-1, options.Port);
        }
开发者ID:chrisumbel,项目名称:Configuration,代码行数:31,代码来源:CloudFoundryOptionsTest.cs

示例3: IdentityOptionsFromConfig

        public void IdentityOptionsFromConfig()
        {
            const string roleClaimType = "rolez";
            const string usernameClaimType = "namez";
            const string useridClaimType = "idz";
            const string securityStampClaimType = "stampz";

            var dic = new Dictionary<string, string>
            {
                {"identity:claimsidentity:roleclaimtype", roleClaimType},
                {"identity:claimsidentity:usernameclaimtype", usernameClaimType},
                {"identity:claimsidentity:useridclaimtype", useridClaimType},
                {"identity:claimsidentity:securitystampclaimtype", securityStampClaimType},
                {"identity:user:requireUniqueEmail", "true"},
                {"identity:password:RequiredLength", "10"},
                {"identity:password:RequireNonAlphanumeric", "false"},
                {"identity:password:RequireUpperCase", "false"},
                {"identity:password:RequireDigit", "false"},
                {"identity:password:RequireLowerCase", "false"},
                {"identity:lockout:AllowedForNewUsers", "FALSe"},
                {"identity:lockout:MaxFailedAccessAttempts", "1000"}
            };
            var builder = new ConfigurationBuilder();
            builder.AddInMemoryCollection(dic);
            var config = builder.Build();
            Assert.Equal(roleClaimType, config["identity:claimsidentity:roleclaimtype"]);

            var services = new ServiceCollection();
            services.AddIdentity<TestUser,TestRole>();
            services.Configure<IdentityOptions>(config.GetSection("identity"));
            var accessor = services.BuildServiceProvider().GetRequiredService<IOptions<IdentityOptions>>();
            Assert.NotNull(accessor);
            var options = accessor.Value;
            Assert.Equal(roleClaimType, options.ClaimsIdentity.RoleClaimType);
            Assert.Equal(useridClaimType, options.ClaimsIdentity.UserIdClaimType);
            Assert.Equal(usernameClaimType, options.ClaimsIdentity.UserNameClaimType);
            Assert.Equal(securityStampClaimType, options.ClaimsIdentity.SecurityStampClaimType);
            Assert.True(options.User.RequireUniqueEmail);
            Assert.Equal("ab[email protected]+", options.User.AllowedUserNameCharacters);
            Assert.False(options.Password.RequireDigit);
            Assert.False(options.Password.RequireLowercase);
            Assert.False(options.Password.RequireNonAlphanumeric);
            Assert.False(options.Password.RequireUppercase);
            Assert.Equal(10, options.Password.RequiredLength);
            Assert.False(options.Lockout.AllowedForNewUsers);
            Assert.Equal(1000, options.Lockout.MaxFailedAccessAttempts);
        }
开发者ID:yuyunyan,项目名称:Identity,代码行数:47,代码来源:IdentityOptionsTest.cs

示例4: ConfigureStaticProviderServices

 public static IServiceProvider ConfigureStaticProviderServices()
 {
     var services = new ServiceCollection().AddOptions();
     services.Configure<FakeOptions>(o =>
     {
         o.Configured = true;
         o.Environment = "StaticProvider";
     });
     return services.BuildServiceProvider();
 }
开发者ID:akrisiun,项目名称:Hosting,代码行数:10,代码来源:Startup.cs

示例5: ConfigureServices

        private static void ConfigureServices()
        {
            var services = new ServiceCollection();

            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json");

            _configuration = builder.Build();
            services.Configure<ClientSettings>(_configuration.GetSection("AppSettings"));
            _serviceProvider = services.BuildServiceProvider();
        }
开发者ID:gencebay,项目名称:CloudBuilder,代码行数:12,代码来源:Program.cs

示例6: ConfigureCloudFoundryOptions_With_VCAP_SERVICES_Environment_NotPresent

        public void ConfigureCloudFoundryOptions_With_VCAP_SERVICES_Environment_NotPresent()
        {
            // Arrange
            Environment.SetEnvironmentVariable("VCAP_SERVICES", null);
            var services = new ServiceCollection().AddOptions();
            // Act and Assert

            var builder = new ConfigurationBuilder().AddCloudFoundry();
            var config = builder.Build();

            services.Configure<CloudFoundryServicesOptions>(config);
            var service = services.BuildServiceProvider().GetService<IOptions<CloudFoundryServicesOptions>>();
            Assert.NotNull(service);
            var options = service.Value;
            Assert.NotNull(options);
            Assert.NotNull(options.Services);
            Assert.Equal(0, options.Services.Count);
        }
开发者ID:chrisumbel,项目名称:Configuration,代码行数:18,代码来源:CloudFoundryOptionsTest.cs

示例7: IdentityOptionsActionOverridesConfig

 public void IdentityOptionsActionOverridesConfig()
 {
     var dic = new Dictionary<string, string>
     {
         {"identity:user:requireUniqueEmail", "true"},
         {"identity:lockout:MaxFailedAccessAttempts", "1000"}
     };
     var builder = new ConfigurationBuilder();
     builder.AddInMemoryCollection(dic);
     var config = builder.Build();
     var services = new ServiceCollection();
     services.Configure<IdentityOptions>(config.GetSection("identity"));
     services.AddIdentity<TestUser, TestRole>(o => { o.User.RequireUniqueEmail = false; o.Lockout.MaxFailedAccessAttempts++; });
     var accessor = services.BuildServiceProvider().GetRequiredService<IOptions<IdentityOptions>>();
     Assert.NotNull(accessor);
     var options = accessor.Value;
     Assert.False(options.User.RequireUniqueEmail);
     Assert.Equal(1001, options.Lockout.MaxFailedAccessAttempts);
 }
开发者ID:yuyunyan,项目名称:Identity,代码行数:19,代码来源:IdentityOptionsTest.cs

示例8: CreateNode

        public static Node CreateNode(out IServiceProvider provider)
        {
            IServiceCollection sc = new ServiceCollection();
            sc.AddLogging();
            sc.AddInMemoryRPC();
            sc.AddRaft(p => {
                p.UseLogging = true;
                p.FailureTolerance = -1;
            });
            sc.AddMvc();
            sc.Configure<RaftOptions>(p => { });
            provider = sc.BuildServiceProvider();

            var loggerFactory = provider.GetService<ILoggerFactory>();
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();
            
            return provider.GetService<Node>();
        }
开发者ID:RossMerr,项目名称:Caudex.Rafting,代码行数:20,代码来源:NodeBuilder.cs

示例9: AntiforgeryOptionsSetup_UserOptionsSetup_CanSetCookieName

        public void AntiforgeryOptionsSetup_UserOptionsSetup_CanSetCookieName()
        {
            // Arrange
            var serviceCollection = new ServiceCollection();
            serviceCollection.Configure<AntiforgeryOptions>(o =>
            {
                Assert.Null(o.CookieName);
                o.CookieName = "antiforgery";
            });
            serviceCollection.AddAntiforgery();
            serviceCollection.ConfigureDataProtection(o => o.SetApplicationName("HelloWorldApp"));

            var services = serviceCollection.BuildServiceProvider();
            var options = services.GetRequiredService<IOptions<AntiforgeryOptions>>();

            // Act
            var cookieName = options.Value.CookieName;

            // Assert
            Assert.Equal("antiforgery", cookieName);
        }
开发者ID:5280Software,项目名称:Antiforgery,代码行数:21,代码来源:AntiforgeryOptionsSetupTest.cs

示例10: GetHttpContext

        private static HttpContext GetHttpContext(
            Action<HttpRequest> updateRequest = null,
            Action<MvcOptions> updateOptions = null)
        {
            var httpContext = new DefaultHttpContext();

            if (updateRequest != null)
            {
                updateRequest(httpContext.Request);
            }

            var serviceCollection = new ServiceCollection();
            serviceCollection.AddMvc();
            serviceCollection.AddTransient<ILoggerFactory, LoggerFactory>();

            if (updateOptions != null)
            {
                serviceCollection.Configure(updateOptions);
            }

            httpContext.RequestServices = serviceCollection.BuildServiceProvider();
            return httpContext;
        }
开发者ID:phinq19,项目名称:git_example,代码行数:23,代码来源:ModelBindingTestHelper.cs

示例11: CreateDefaultServiceCollection

		private ServiceCollection CreateDefaultServiceCollection(
			Action<DepsOptions> configureOptions = null,
			string depsFileName = null,
			bool isDevelopment = false)
		{
			var services = new ServiceCollection();

			services.AddOptions();

			services.AddSingleton<IMemoryCache>(new MemoryCache(new OptionsWrapper<MemoryCacheOptions>(new MemoryCacheOptions())));

			services.Configure<DepsOptions>((opts) =>
			{
				//opts.WebRoot = "testwebroot/";
				if (depsFileName != null)
				{
					opts.DepsFileName = depsFileName;
				}
			});
			services.Configure(
				configureOptions ??
				((DepsOptions _) => { }));

			var path = Path.GetFullPath(Path.GetDirectoryName(Path.Combine(Path.GetFullPath("testwebroot"), "../../../../../")));
			var webrootPath = Path.Combine(path, "testwebroot");
			var approotPath = Path.Combine(path, "testapproot");

			var env = new Mock<IHostingEnvironment>();
			env.Setup(m => m.ContentRootPath).Returns(path);
			env
				.Setup(m => m.EnvironmentName)
				.Returns(isDevelopment ? EnvironmentName.Development : EnvironmentName.Production);
			env.Setup(m => m.WebRootPath).Returns(webrootPath);
			env.Setup(m => m.WebRootFileProvider).Returns(new PhysicalFileProvider(webrootPath));
			services.AddSingleton(env.Object);

			var appRootFileProviderAccessor = new Mock<IAppRootFileProviderAccessor>();
			appRootFileProviderAccessor
				.Setup(m => m.AppRootFileProvider)
				.Returns(new PhysicalFileProvider(approotPath));
			services.AddSingleton(appRootFileProviderAccessor.Object);

			var httpContextAccessor = new Mock<IHttpContextAccessor>();
			httpContextAccessor.Setup(m => m.HttpContext).Returns((HttpContext)null);
			services.AddSingleton(httpContextAccessor.Object);

			var matcherMock = new Mock<Matcher>();
			matcherMock.Setup(m => m.AddInclude(It.IsAny<string>())).Returns((string _) => matcherMock.Object);
			matcherMock.Setup(m => m.AddExclude(It.IsAny<string>())).Returns((string _) => matcherMock.Object);
			matcherMock.Setup(m => m.Execute(It.IsAny<DirectoryInfoBase>())).Returns((DirectoryInfoBase _) => new PatternMatchingResult(new FilePatternMatch[0]));
			services.AddSingleton(matcherMock.Object);

			services.AddSingleton<DepsManager>();
			return services;
		}
开发者ID:mrahhal,项目名称:MR.AspNet.Deps,代码行数:55,代码来源:DepsManagerTest.cs

示例12: CreateVirtualPathContext

        private static VirtualPathContext CreateVirtualPathContext(
            RouteValueDictionary values,
            Action<RouteOptions> options = null,
            string routeName = null)
        {
            var services = new ServiceCollection();
            services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
            services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
            services.AddOptions();
            services.AddRouting();
            if (options != null)
            {
                services.Configure<RouteOptions>(options);
            }

            var context = new DefaultHttpContext
            {
                RequestServices = services.BuildServiceProvider(),
            };

            return new VirtualPathContext(
                context,
                ambientValues: null,
                values: values,
                routeName: routeName);
        }
开发者ID:Corays,项目名称:Routing,代码行数:26,代码来源:RouteCollectionTest.cs

示例13: ServiceCollection

        public void ConfigureCloudFoundryOptions_With_VCAP_APPLICATION_Environment_ConfiguresCloudFoundryApplicationOptions()
        {
            // Arrange
            var environment = @"
{
 
  'application_id': 'fa05c1a9-0fc1-4fbd-bae1-139850dec7a3',
  'application_name': 'my-app',
  'application_uris': [
    'my-app.10.244.0.34.xip.io'
  ],
  'application_version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca',
  'limits': {
    'disk': 1024,
    'fds': 16384,
    'mem': 256
  },
  'name': 'my-app',
  'space_id': '06450c72-4669-4dc6-8096-45f9777db68a',
  'space_name': 'my-space',
  'uris': [
    'my-app.10.244.0.34.xip.io',
    'my-app2.10.244.0.34.xip.io'
  ],
  'users': null,
  'version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca'
}";

            // Arrange
            Environment.SetEnvironmentVariable("VCAP_APPLICATION", environment);
            var services = new ServiceCollection().AddOptions();
            // Act and Assert

            var builder = new ConfigurationBuilder().AddCloudFoundry();
            var config = builder.Build();

            services.Configure<CloudFoundryApplicationOptions>(config);
            var service = services.BuildServiceProvider().GetService<IOptions<CloudFoundryApplicationOptions>>();
            Assert.NotNull(service);
            var options = service.Value;
            Assert.Equal("fa05c1a9-0fc1-4fbd-bae1-139850dec7a3", options.ApplicationId);
            Assert.Equal("my-app", options.ApplicationName);

            Assert.NotNull(options.ApplicationUris);
            Assert.Equal(1, options.ApplicationUris.Length);
            Assert.Equal("my-app.10.244.0.34.xip.io", options.ApplicationUris[0]);

            Assert.Equal("fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca", options.ApplicationVersion);
            Assert.Equal("my-app", options.Name);
            Assert.Equal("06450c72-4669-4dc6-8096-45f9777db68a", options.SpaceId);
            Assert.Equal("my-space", options.SpaceName);

            Assert.NotNull(options.Uris);
            Assert.Equal(2, options.Uris.Length);
            Assert.Equal("my-app.10.244.0.34.xip.io", options.Uris[0]);
            Assert.Equal("my-app2.10.244.0.34.xip.io", options.Uris[1]);

            Assert.Equal("fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca", options.Version);
        }
开发者ID:chrisumbel,项目名称:Configuration,代码行数:59,代码来源:CloudFoundryOptionsTest.cs

示例14: SetupCallsInOrder

        public void SetupCallsInOrder()
        {
            var services = new ServiceCollection().AddOptions();
            var dic = new Dictionary<string, string>
            {
                {"Message", "!"},
            };
            var builder = new ConfigurationBuilder().AddInMemoryCollection(dic);
            var config = builder.Build();
            services.Configure<FakeOptions>(o => o.Message += "Igetstomped");
            services.Configure<FakeOptions>(config);
            services.Configure<FakeOptions>(o => o.Message += "a");
            services.ConfigureOptions(typeof(FakeOptionsSetupA));
            services.ConfigureOptions(new FakeOptionsSetupB());
            services.ConfigureOptions<FakeOptionsSetupC>();
            services.Configure<FakeOptions>(o => o.Message += "z");

            var service = services.BuildServiceProvider().GetService<IOptions<FakeOptions>>();
            Assert.NotNull(service);
            var options = service.Value;
            Assert.NotNull(options);
            Assert.Equal("!aABCz", options.Message);
        }
开发者ID:leloulight,项目名称:Options,代码行数:23,代码来源:OptionsTest.cs

示例15: Configure_GetsEnumOptionsFromConfiguration

        public void Configure_GetsEnumOptionsFromConfiguration(
            IDictionary<string, string> configValues,
            IDictionary<string, object> expectedValues)
        {
            // Arrange
            var services = new ServiceCollection().AddOptions();
            var builder = new ConfigurationBuilder().AddInMemoryCollection(configValues);
            var config = builder.Build();
            services.Configure<EnumOptions>(config);

            // Act
            var options = services.BuildServiceProvider().GetService<IOptions<EnumOptions>>().Value;

            // Assert
            var optionsProps = options.GetType().GetProperties().ToDictionary(p => p.Name);
            var assertions = expectedValues
                .Select(_ => new Action<KeyValuePair<string, object>>(kvp =>
                    Assert.Equal(kvp.Value, optionsProps[kvp.Key].GetValue(options))));
            Assert.Collection(expectedValues, assertions.ToArray());
        }
开发者ID:leloulight,项目名称:Options,代码行数:20,代码来源:OptionsTest.cs


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