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


C# UnityContainer.AddNewExtension方法代码示例

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


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

示例1: CanConfigureRemotingInterceptionOnInterface

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

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

示例2: 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

示例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: CanUseContainerToResolveFactoryParameters

        public void CanUseContainerToResolveFactoryParameters()
        {
            bool factoryWasCalled = false;
            string connectionString = "Northwind";

            IUnityContainer container = new UnityContainer();

            container.AddNewExtension<StaticFactoryExtension>()
                .Configure<IStaticFactoryConfiguration>()
                    .RegisterFactory<MockDatabase>(c =>
                    {
                        Assert.AreSame(container, c);
                        factoryWasCalled = true;
                        string cs = c.Resolve<string>("connectionString");
                        return MockDatabase.Create(cs);
                    })
                    .Container
                .RegisterInstance<string>("connectionString", connectionString);

            MockDatabase db = container.Resolve<MockDatabase>();

            Assert.IsTrue(factoryWasCalled);
            Assert.IsNotNull(db);
            Assert.AreEqual(connectionString, db.ConnectionString);
        }
开发者ID:kangkot,项目名称:unity,代码行数:25,代码来源:StaticFactoryFixture.cs

示例5: CanConfigureDefaultRemotingInterceptionOnMBRO

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

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

示例6: CanInterceptGenericMethodWithHandlerAttributeThroughInterface

        public void CanInterceptGenericMethodWithHandlerAttributeThroughInterface()
        {
            var container = new UnityContainer();
            container.AddNewExtension<Interception>();
            container.RegisterType<IInterfaceWithGenericMethod, ClassWithGenericMethod>(
                new Interceptor(new TransparentProxyInterceptor()));

            var instance = container.Resolve<IInterfaceWithGenericMethod>();

            var result = instance.DoSomething<int>();

            Assert.AreEqual(0, result);
        }
开发者ID:theoju,项目名称:CleanCode,代码行数:13,代码来源:IntegrationFixture.cs

示例7: 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

示例8: AttributeDrivenPolicyIsAddedByDefault

        public void AttributeDrivenPolicyIsAddedByDefault()
        {
            GlobalCountCallHandler.Calls.Clear();

            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();
            container.RegisterType<Interface, WrappableThroughInterfaceWithAttributes>(
                new Interceptor<InterfaceInterceptor>(),
                new InterceptionBehavior<PolicyInjectionBehavior>());

            Interface wrappedOverInterface = container.Resolve<Interface>();
            wrappedOverInterface.Method();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["WrappableThroughInterfaceWithAttributes-Method"]);
        }
开发者ID:theoju,项目名称:CleanCode,代码行数:15,代码来源:InterceptionFixture.cs

示例9: ConfiguringDefaultRemotingInterceptionOnNonMBROTypeThrows

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

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

示例10: CanSetUpInterceptorThroughInjectionMemberForExistingInterceptor

        public void CanSetUpInterceptorThroughInjectionMemberForExistingInterceptor()
        {
            CallCountInterceptionBehavior interceptionBehavior = new CallCountInterceptionBehavior();

            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<Interception>();

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

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

            instance.DoSomething("1");

            Assert.AreEqual(1, interceptionBehavior.CallCount);
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:18,代码来源:InterceptionConfigurationFixture.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: CanSetUpAdditionalInterfaceThroughInjectionMemberForInstanceInterception

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

            int invokeCount = 0;

            container.RegisterType<IInterface, BaseClass>(
                "test",
                new Interceptor<InterfaceInterceptor>(),
                new AdditionalInterface(typeof(IOtherInterface)),
                new InterceptionBehavior(
                    new DelegateInterceptionBehavior(
                        (mi, gn) => { invokeCount++; return mi.CreateMethodReturn(0); })));

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

            ((IOtherInterface)instance).DoSomethingElse("1");

            Assert.AreEqual(1, invokeCount);
        }
开发者ID:theoju,项目名称:CleanCode,代码行数:21,代码来源:InterceptionConfigurationFixture.cs

示例13: 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

示例14: CanSetUpAPolicyWithGivenRulesAndHandlers

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

            IMatchingRule rule1 = new AlwaysMatchingRule();
            ICallHandler handler1 = new CallCountHandler();

            container
                .Configure<Interception>()
                    .AddPolicy("policy1")
                        .AddMatchingRule(rule1)
                        .AddCallHandler(handler1);

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

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

            Assert.AreEqual(1, ((CallCountHandler)handler1).CallCount);
        }
开发者ID:kangkot,项目名称:unity,代码行数:23,代码来源:ConvenienceConfigurationFixture.cs

示例15: CanInterceptMBROWithDependencyOnOtherMBRO

        public void CanInterceptMBROWithDependencyOnOtherMBRO()
        {
            GlobalCountCallHandler.Calls.Clear();

            IUnityContainer container = new UnityContainer();

            container.AddNewExtension<Interception>();

            container
                .RegisterInstance<IMatchingRule>(
                    "parentRule",
                    new TypeMatchingRule(typeof(WrappableWithProperty)))
                .RegisterInstance<IMatchingRule>(
                    "childRule",
                    new TypeMatchingRule(typeof(Wrappable)))
                .RegisterInstance<ICallHandler>(
                    "parentCallHandler",
                    new GlobalCountCallHandler("parent"))
                .RegisterInstance<ICallHandler>(
                    "childCallHandler",
                    new GlobalCountCallHandler("child"))
                .RegisterType<InjectionPolicy, RuleDrivenPolicy>("parentPolicy",
                    new InjectionConstructor(
                        new ResolvedArrayParameter<IMatchingRule>(
                            new ResolvedParameter<IMatchingRule>("parentRule")),
                        new string[] { "parentCallHandler" }))
                .RegisterType<InjectionPolicy, RuleDrivenPolicy>("childPolicy",
                    new InjectionConstructor(
                        new ResolvedArrayParameter<IMatchingRule>(
                            new ResolvedParameter<IMatchingRule>("childRule")),
                        new string[] { "childCallHandler" }))
                .RegisterType<WrappableWithProperty>(new InjectionProperty("Wrappable"))
                .Configure<Interception>()
                    .SetDefaultInterceptorFor<WrappableWithProperty>(new TransparentProxyInterceptor())
                    .SetDefaultInterceptorFor<Wrappable>(new TransparentProxyInterceptor());

            WrappableWithProperty instance = container.Resolve<WrappableWithProperty>();

            instance.Method();
            Assert.AreEqual(1, GlobalCountCallHandler.Calls["parent"]); // method

            instance.Wrappable.Method();
            Assert.AreEqual(2, GlobalCountCallHandler.Calls["parent"]); // method and getter
            Assert.AreEqual(1, GlobalCountCallHandler.Calls["child"]);
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:45,代码来源:InterceptionFixture.cs


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