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


C# Container.GetProfile方法代码示例

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


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

示例1: profile_name

        public void profile_name()
        {
            var container = new Container();
            container.ProfileName.ShouldBe("DEFAULT");

            container.GetProfile("Blue").ProfileName.ShouldBe("Blue");

            container.GetProfile("Blue").GetNestedContainer().ProfileName.ShouldBe("Blue - Nested");
        }
开发者ID:khellang,项目名称:structuremap,代码行数:9,代码来源:Container_role_assignment_and_profile_name_Tester.cs

示例2: setter_policies_should_be_applied_in_profile_container

        public void setter_policies_should_be_applied_in_profile_container()
        {
            var container = new Container(cfg => { cfg.Policies.SetAllProperties(x => x.OfType<Injected>()); });

            var product = container.GetProfile("Foo").GetInstance<Product>();
            product.Inject.ShouldNotBeNull();
        }
开发者ID:khellang,项目名称:structuremap,代码行数:7,代码来源:Setter_policies_when_the_build_plan_is_created_by_a_nested_container.cs

示例3: AddAProfileWithInlineInstanceDefinition

        public void AddAProfileWithInlineInstanceDefinition()
        {
            string theProfileName = "TheProfile";

            var container = new Container(registry => {
                registry.For<IWidget>().Use(new NamedWidget("default"));

                registry.Profile(theProfileName, x =>
                {
                    x.For<IWidget>().Use<AWidget>();
                });
            });

            container.GetProfile(theProfileName).GetInstance<IWidget>().ShouldBeOfType<AWidget>();
        }
开发者ID:smerrell,项目名称:structuremap,代码行数:15,代码来源:profiles_acceptance_tester.cs

示例4: Add_default_instance_by_lambda

        public void Add_default_instance_by_lambda()
        {
            string theProfileName = "something";

            IContainer container = new Container(r =>
            {
                r.Profile(theProfileName, x =>
                {
                    x.For<IWidget>().Use(() => new AWidget());
                    x.For<Rule>().Use(() => new DefaultRule());
                });

            });

            var profile = container.GetProfile(theProfileName);

            profile.GetInstance<IWidget>().ShouldBeOfType<AWidget>();
            profile.GetInstance<Rule>().ShouldBeOfType<DefaultRule>();
        }
开发者ID:smerrell,项目名称:structuremap,代码行数:19,代码来源:profiles_acceptance_tester.cs

示例5: AddAProfileWithANamedDefault

        public void AddAProfileWithANamedDefault()
        {
            string theProfileName = "TheProfile";
            string theDefaultName = "TheDefaultName";

            var registry = new Registry();

            registry.For<IWidget>().Add(new NamedWidget(theDefaultName)).Named(theDefaultName);
            registry.For<IWidget>().Use<AWidget>();

            registry.Profile(theProfileName, p => {
                p.For<IWidget>().Use(theDefaultName);
                p.For<Rule>().Use("DefaultRule");
            });

            var container = new Container(registry);
            container.GetProfile(theProfileName).GetInstance<IWidget>().ShouldBeOfType<NamedWidget>()
                     .Name.ShouldEqual(theDefaultName);
        }
开发者ID:smerrell,项目名称:structuremap,代码行数:19,代码来源:profiles_acceptance_tester.cs

示例6: nested_container_from_profile

        public void nested_container_from_profile()
        {
            var parent = new Container(_ =>
            {
                _.AddRegistry<ProfileRegistry>();
            });

            // Create a child container and override the
            // IService registration
            var child = parent.GetProfile("my-profile");

            using (var nested = child.GetNestedContainer())
            {
                nested.GetInstance<IService>()
                    .ShouldBeOfType<AService>();
            }

            using (var nested = child.GetNestedContainer())
            {
                nested.GetInstance<IService>()
                    .ShouldBeOfType<AService>();
            }
        }
开发者ID:khellang,项目名称:structuremap,代码行数:23,代码来源:disposing_nested_container_created_from_profile.cs

示例7: display_one_service_for__a_profile_container

        public void display_one_service_for__a_profile_container()
        {
            var container = new Container(x =>
            {
                x.For<IEngine>().Use<Hemi>().Named("The Hemi");

                x.For<IEngine>().Add<VEight>().Singleton().Named("V8");
                x.For<IEngine>().Add<FourFiftyFour>().AlwaysUnique();
                x.For<IEngine>().Add<StraightSix>().LifecycleIs<ThreadLocalStorageLifecycle>();

                x.For<IEngine>().Add(() => new Rotary()).Named("Rotary");
                x.For<IEngine>().Add(c => c.GetInstance<PluginElectric>());

                x.For<IEngine>().Add(new InlineFour());

                x.Profile("Blue", blue => {
                    blue.For<IEngine>().Use<FourFiftyFour>().Named("Gas Guzzler");
                });
            });

            Debug.WriteLine(container.GetProfile("Blue").WhatDoIHave());
        }
开发者ID:KevM,项目名称:structuremap,代码行数:22,代码来源:WhatDoIHave_Smoke_Tester.cs

示例8: nested_container_from_profile_container

        public void nested_container_from_profile_container()
        {
            var container = new Container(x =>
            {
                x.For<IColor>().Use<Red>();

                x.Profile("Blue", _ => _.For<IColor>().Use<Blue>());
                x.Profile("Green", _ => _.For<IColor>().Use<Green>());
            });

            using (var nested = container.GetProfile("Blue").GetNestedContainer())
            {
                nested.GetInstance<IColor>().ShouldBeOfType<Blue>();
            }

            using (var nested = container.GetNestedContainer("Green"))
            {
                nested.GetInstance<IColor>().ShouldBeOfType<Green>();
            }
        }
开发者ID:wolfascu,项目名称:structuremap,代码行数:20,代码来源:nested_containers.cs

示例9: Add_default_instance_with_concrete_type

        public void Add_default_instance_with_concrete_type()
        {
            string theProfileName = "something";

            IContainer container = new Container(registry =>
            {
                registry.Profile(theProfileName, p =>
                {
                    p.For<IWidget>().Use<AWidget>();
                    p.For<Rule>().Use<DefaultRule>();
                });

            });

            var profile = container.GetProfile(theProfileName);

            profile.GetInstance<IWidget>().ShouldBeOfType<AWidget>();
            profile.GetInstance<Rule>().ShouldBeOfType<DefaultRule>();
        }
开发者ID:smerrell,项目名称:structuremap,代码行数:19,代码来源:profiles_acceptance_tester.cs


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