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


C# ServiceCollection.Configure方法代码示例

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


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

示例1: ConfigureProviderArgsServices

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

示例2: CreateContainer

        public IServiceProvider CreateContainer(ShellSettings settings, ShellBlueprint blueprint) {
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped<IOrchardShell, DefaultOrchardShell>();
            serviceCollection.AddScoped<IRouteBuilder, DefaultShellRouteBuilder>();
            serviceCollection.AddInstance(settings);
            serviceCollection.AddInstance(blueprint.Descriptor);
            serviceCollection.AddInstance(blueprint);

            serviceCollection.AddMvc();

            serviceCollection.Configure<RazorViewEngineOptions>(options => {
                var expander = new ModuleViewLocationExpander();
                options.ViewLocationExpanders.Add(expander);
            });

            var p = _serviceProvider.GetService<IOrchardLibraryManager>();
            serviceCollection.AddInstance<IAssemblyProvider>(new DefaultAssemblyProviderTest(p, _serviceProvider, _serviceProvider.GetService<IAssemblyLoaderContainer>()));

            foreach (var dependency in blueprint.Dependencies) {
                foreach (var interfaceType in dependency.Type.GetInterfaces()
                    .Where(itf => typeof(IDependency).IsAssignableFrom(itf))) {
                    Logger.Debug("Type: {0}, Interface Type: {1}", dependency.Type, interfaceType);

                    if (typeof(ISingletonDependency).IsAssignableFrom(interfaceType)) {
                        serviceCollection.AddSingleton(interfaceType, dependency.Type);
                    }
                    else if (typeof(IUnitOfWorkDependency).IsAssignableFrom(interfaceType)) {
                        serviceCollection.AddScoped(interfaceType, dependency.Type);
                    }
                    else if (typeof (ITransientDependency).IsAssignableFrom(interfaceType)) {
                        serviceCollection.AddTransient(interfaceType, dependency.Type);
                    }
                    else {
                        serviceCollection.AddScoped(interfaceType, dependency.Type);
                    }
                }
            }

            //foreach (var item in blueprint.Controllers) {
            //    var serviceKeyName = (item.AreaName + "/" + item.ControllerName).ToLowerInvariant();
            //    var serviceKeyType = item.Type;
            //    serviceCollection.AddScoped(serviceKeyType);

            //}

            return BuildFallbackServiceProvider(
                            serviceCollection,
                            _serviceProvider);
        }
开发者ID:night-king,项目名称:OrchardNoCMS,代码行数:50,代码来源:ShellContainerFactory.cs

示例3: CreateServiceProvider

        private static IServiceProvider CreateServiceProvider()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-gb");
            var builder = new ConfigurationBuilder().AddUserSecrets();
            var configuration = builder.Build();

            var services = new ServiceCollection();

            services.AddWarcraft();
            services.AddBattleNetCache();
            services.Configure<BattleNetClientOptions>(options =>
            {
                options.ApiKey = configuration["Authentication:BattleNet:Key"];
                options.ParseApiResponseInformation = true;
                options.ThrowErrorOnMissingMembers = true;
            });

            return services.BuildServiceProvider();
        }
开发者ID:sherif-elmetainy,项目名称:wowsharp,代码行数:19,代码来源:TestHelper.cs

示例4: 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:qiudesong,项目名称:Antiforgery,代码行数:21,代码来源:AntiforgeryOptionsSetupTest.cs

示例5: GetConstraintResolver

 private static IInlineConstraintResolver GetConstraintResolver()
 {
     var services = new ServiceCollection().AddOptions();
     services.Configure<RouteOptions>(options =>
                         options
                         .ConstraintMap
                         .Add("test", typeof(TestRouteConstraint)));
     var serviceProvider = services.BuildServiceProvider();
     var accessor = serviceProvider.GetRequiredService<IOptions<RouteOptions>>();
     return new DefaultInlineConstraintResolver(accessor);
 }
开发者ID:nbilling,项目名称:Routing,代码行数:11,代码来源:InlineRouteParameterParserTests.cs

示例6: 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:liujiekm,项目名称:Options,代码行数:23,代码来源:OptionsTest.cs

示例7: Configure_GetsNullableOptionsFromConfiguration

        public void Configure_GetsNullableOptionsFromConfiguration(
            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<NullableOptions>(config);

            // Act
            var options = services.BuildServiceProvider().GetService<IOptions<NullableOptions>>().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:liujiekm,项目名称:Options,代码行数:20,代码来源:OptionsTest.cs

示例8: SetupTargetOptionsNameIsNotCaseSensitive

        public void SetupTargetOptionsNameIsNotCaseSensitive()
        {
            var services = new ServiceCollection().AddOptions();
            services.Configure<FakeOptions>(o => o.Message += "B", -100, "abc");

            var service = services.BuildServiceProvider().GetService<IOptions<FakeOptions>>();

            var options2 = service.GetNamedOptions("ABC");
            Assert.NotNull(options2);
            Assert.Equal("B", options2.Message);

            var options3 = service.GetNamedOptions("aBc");
            Assert.NotNull(options3);
            Assert.Equal("B", options3.Message);
        }
开发者ID:lingyunzhi12345,项目名称:Options,代码行数:15,代码来源:OptionsTest.cs

示例9: NullNamesAreAlwaysApplied

        public void NullNamesAreAlwaysApplied()
        {
            const string TargetOptionsName = "Name";
            var services = new ServiceCollection().AddOptions();
            services.Configure<FakeOptions>(o => o.Message += "a");
            services.Configure<FakeOptions>(o => o.Message += "N", TargetOptionsName);

            var service = services.BuildServiceProvider().GetService<IOptions<FakeOptions>>();
            Assert.NotNull(service);
            var options = service.Options;
            Assert.NotNull(options);
            Assert.Equal("a", options.Message);
            var namedOption = service.GetNamedOptions(TargetOptionsName);
            Assert.NotNull(namedOption);
            Assert.Equal("aN", namedOption.Message);
        }
开发者ID:lingyunzhi12345,项目名称:Options,代码行数:16,代码来源:OptionsTest.cs

示例10: NamedSetupDoNotCollideWithEachOther

        public void NamedSetupDoNotCollideWithEachOther()
        {
            var services = new ServiceCollection().AddOptions();
            var dic = new Dictionary<string, string>
            {
                {"Message", "!"},
            };
            var builder = new ConfigurationBuilder(new MemoryConfigurationSource(dic));
            var config = builder.Build();

            services.ConfigureOptions(new FakeOptionsSetupB { Name = "2" });
            services.Configure<FakeOptions>(o => o.Message += "Z", 10000, "2");

            services.ConfigureOptions(new FakeOptionsSetupB { Name = "3" });
            services.Configure<FakeOptions>(config, "3");
            services.Configure<FakeOptions>(o => o.Message += "z", 10000, "3");

            var service = services.BuildServiceProvider().GetService<IOptions<FakeOptions>>();
            Assert.NotNull(service);
            var options = service.Options;
            Assert.NotNull(options);
            Assert.Equal("", options.Message);

            var options2 = service.GetNamedOptions("2");
            Assert.NotNull(options2);
            Assert.Equal("BZ", options2.Message);

            var options3 = service.GetNamedOptions("3");
            Assert.NotNull(options3);
            Assert.Equal("!Bz", options3.Message);
        }
开发者ID:lingyunzhi12345,项目名称:Options,代码行数:31,代码来源:OptionsTest.cs


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