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


C# UnityContainer.Configure方法代码示例

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


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

示例1: CanSetUpAPolicyWithExternallyConfiguredRulesAndHandlers

        public void CanSetUpAPolicyWithExternallyConfiguredRulesAndHandlers()
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

            container
                .Configure<Interception>()
                    .AddPolicy("policy1")
                        .AddMatchingRule("rule1")
                        .AddCallHandler("handler1")
                        .AddCallHandler("handler2").Interception.Container
                .RegisterType<IMatchingRule, AlwaysMatchingRule>("rule1")
                .RegisterType<ICallHandler, GlobalCountCallHandler>(
                    "handler1",
                    new InjectionConstructor("handler1"))
                .RegisterType<ICallHandler, GlobalCountCallHandler>(
                    "handler2",
                    new InjectionConstructor("handler2"),
                    new InjectionProperty("Order", 10));

            GlobalCountCallHandler.Calls.Clear();

            container
                .Configure<Interception>()
                    .SetInterceptorFor<Wrappable>("wrappable", new VirtualMethodInterceptor());

            Wrappable wrappable1 = container.Resolve<Wrappable>("wrappable");
            wrappable1.Method2();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler1"]);
            Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler2"]);
        }
开发者ID:theoju,项目名称:CleanCode,代码行数:32,代码来源:ConvenienceConfigurationFixture.cs

示例2: CanConfigureRemotingInterceptionOnInterface

        public void CanConfigureRemotingInterceptionOnInterface()
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

            container.Configure<Interception>().SetInterceptorFor<Interface>(new TransparentProxyInterceptor());
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:7,代码来源:InterceptionFixture.cs

示例3: CanAddExtensionWithNonDefaultConstructor

 public void CanAddExtensionWithNonDefaultConstructor()
 {
     IUnityContainer container = new UnityContainer();
     container.AddNewExtension<ContainerExtensionWithNonDefaultConstructor>();
     var extension = container.Configure(typeof (ContainerExtensionWithNonDefaultConstructor));
     Assert.IsNotNull(extension);
 }
开发者ID:theoju,项目名称:CleanCode,代码行数:7,代码来源:UnityExtensionFixture.cs

示例4: CanConfigureDefaultRemotingInterceptionOnMBRO

        public void CanConfigureDefaultRemotingInterceptionOnMBRO()
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

            container.Configure<Interception>()
                .SetDefaultInterceptorFor<Wrappable>(new TransparentProxyInterceptor());
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:8,代码来源:InterceptionFixture.cs

示例5: CanGetExtensionConfigurationFromContainer

        public void CanGetExtensionConfigurationFromContainer()
        {
            IUnityContainer container = new UnityContainer()
                .AddNewExtension<StaticFactoryExtension>();

            IStaticFactoryConfiguration config = container.Configure<IStaticFactoryConfiguration>();

            Assert.IsNotNull(config);
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:9,代码来源:StaticFactoryFixture.cs

示例6: CanLookupExtensionByClassName

        public void CanLookupExtensionByClassName()
        {
            MockContainerExtension extension = new MockContainerExtension();
            IUnityContainer container = new UnityContainer();
            container.AddExtension(extension);

            MockContainerExtension result = container.Configure<MockContainerExtension>();

            Assert.AreSame(extension, result);
        }
开发者ID:theoju,项目名称:CleanCode,代码行数:10,代码来源:UnityExtensionFixture.cs

示例7: CanGetConfigurationWithoutGenericMethod

        public void CanGetConfigurationWithoutGenericMethod()
        {
            MockContainerExtension extension = new MockContainerExtension();
            IUnityContainer container = new UnityContainer()
                .AddExtension(extension);

            IMockConfiguration config = (IMockConfiguration)container.Configure(typeof(IMockConfiguration));

            Assert.AreSame(extension, config);
            Assert.AreSame(container, config.Container);
        }
开发者ID:theoju,项目名称:CleanCode,代码行数:11,代码来源:UnityExtensionFixture.cs

示例8: CanGetConfigurationInterfaceFromExtension

        public void CanGetConfigurationInterfaceFromExtension()
        {
            MockContainerExtension extension = new MockContainerExtension();
            IUnityContainer container = new UnityContainer()
                .AddExtension(extension);

            IMockConfiguration config = container.Configure<IMockConfiguration>();

            Assert.AreSame(extension, config);
            Assert.AreSame(container, config.Container);
        }
开发者ID:theoju,项目名称:CleanCode,代码行数:11,代码来源:UnityExtensionFixture.cs

示例9: SettingUpRuleWithEmptyNameThrows

        public void SettingUpRuleWithEmptyNameThrows()
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

            try
            {
                container.Configure<Interception>().AddPolicy(string.Empty);
                Assert.Fail("should have thrown");
            }
            catch (ArgumentException)
            {
            }
        }
开发者ID:shhyder,项目名称:MapApplication,代码行数:14,代码来源:ConvenienceConfigurationFixture.cs

示例10: ConfiguringRemotingInterceptionOnNonMBROTypeThrows

        public void ConfiguringRemotingInterceptionOnNonMBROTypeThrows()
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

            try
            {
                container.Configure<Interception>()
                    .SetInterceptorFor<WrappableThroughInterface>(new TransparentProxyInterceptor());
                Assert.Fail("Call to SetInjectorFor<T>() should have thrown");
            }
            catch (ArgumentException)
            {
                // expected exception
            }
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:16,代码来源:InterceptionFixture.cs

示例11: CanSetUpAnEmptyRule

        public void CanSetUpAnEmptyRule()
        {
            // there is no visible effect for this, but it should still be resolved.
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

            // empty
            container
                .Configure<Interception>()
                    .AddPolicy("policy1");

            List<InjectionPolicy> policies
                = new List<InjectionPolicy>(container.ResolveAll<InjectionPolicy>());

            Assert.AreEqual(2, policies.Count);
            Assert.IsInstanceOfType(policies[0], typeof(AttributeDrivenPolicy));
            Assert.IsInstanceOfType(policies[1], typeof(RuleDrivenPolicy));
            Assert.AreEqual("policy1", policies[1].Name);
        }
开发者ID:shhyder,项目名称:MapApplication,代码行数:19,代码来源:ConvenienceConfigurationFixture.cs

示例12: CanSetUpInterceptorThroughInjectionMember

        public void CanSetUpInterceptorThroughInjectionMember()
        {
            CallCountHandler handler = new CallCountHandler();

            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();
            container.Configure<Interception>()
                .AddPolicy("policy")
                    .AddMatchingRule<AlwaysMatchingRule>()
                    .AddCallHandler(handler);

            container.RegisterType<IInterface, BaseClass>(
                "test",
                new Interceptor<InterfaceInterceptor>(),
                new InterceptionBehavior<PolicyInjectionBehavior>());

            IInterface instance = container.Resolve<IInterface>("test");

            instance.DoSomething("1");

            Assert.AreEqual(1, handler.CallCount);
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:22,代码来源:InterceptionConfigurationFixture.cs

示例13: SettingUpAPolicyWithANullRuleElementThrows

        public void SettingUpAPolicyWithANullRuleElementThrows()
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

            try
            {
                container
                    .Configure<Interception>()
                        .AddPolicy("policy1")
                            .AddMatchingRule(typeof(AlwaysMatchingRule))
                            .AddMatchingRule((string)null)
                            .AddCallHandler(new CallCountHandler());
                Assert.Fail("Should have thrown");
            }
            catch (ArgumentException)
            {
            }
        }
开发者ID:shhyder,项目名称:MapApplication,代码行数:19,代码来源:ConvenienceConfigurationFixture.cs

示例14: CanSetUpAPolicyWithLifetimeManagedNamedInjectedRulesAndHandlers

        public void CanSetUpAPolicyWithLifetimeManagedNamedInjectedRulesAndHandlers()
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

            container
                .Configure<Interception>()
                    .AddPolicy("policy1")
                        .AddMatchingRule<AlwaysMatchingRule>(
                            "rule1",
                            new ContainerControlledLifetimeManager())
                        .AddCallHandler<CallCountHandler>(
                            "handler1",
                            (LifetimeManager)null)
                        .AddCallHandler<CallCountHandler>(
                            "handler2",
                            new ContainerControlledLifetimeManager(),
                            new InjectionProperty("Order", 10));

            GlobalCountCallHandler.Calls.Clear();

            container
                .Configure<Interception>()
                    .SetInterceptorFor<Wrappable>("wrappable", new TransparentProxyInterceptor());

            Wrappable wrappable1 = container.Resolve<Wrappable>("wrappable");
            wrappable1.Method2();

            CallCountHandler handler1 = (CallCountHandler)container.Resolve<ICallHandler>("handler1");
            CallCountHandler handler2 = (CallCountHandler)container.Resolve<ICallHandler>("handler2");

            Assert.AreEqual(0, handler1.CallCount);     // not lifetime maanaged
            Assert.AreEqual(1, handler2.CallCount);     // lifetime managed
        }
开发者ID:shhyder,项目名称:MapApplication,代码行数:34,代码来源:ConvenienceConfigurationFixture.cs

示例15: CanSetUpAPolicyWithNamedInjectedRulesAndHandlers

        public void CanSetUpAPolicyWithNamedInjectedRulesAndHandlers()
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

            container
                .Configure<Interception>()
                    .AddPolicy("policy1")
                        .AddMatchingRule<AlwaysMatchingRule>("rule1")
                        .AddCallHandler<GlobalCountCallHandler>(
                            "handler1",
                            new InjectionConstructor("handler1"))
                        .AddCallHandler<GlobalCountCallHandler>(
                            "handler2",
                            new InjectionConstructor("handler2"),
                            new InjectionProperty("Order", 10));

            GlobalCountCallHandler.Calls.Clear();

            container
                .Configure<Interception>()
                    .SetInterceptorFor<Wrappable>("wrappable", new TransparentProxyInterceptor());

            Wrappable wrappable1 = container.Resolve<Wrappable>("wrappable");
            wrappable1.Method2();

            GlobalCountCallHandler handler1 = (GlobalCountCallHandler)container.Resolve<ICallHandler>("handler1");
            GlobalCountCallHandler handler2 = (GlobalCountCallHandler)container.Resolve<ICallHandler>("handler2");

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler1"]);
            Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler2"]);
            Assert.AreEqual(0, handler1.Order);
            Assert.AreEqual(10, handler2.Order);
        }
开发者ID:shhyder,项目名称:MapApplication,代码行数:34,代码来源:ConvenienceConfigurationFixture.cs


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