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") .RegisterType <InjectionPolicy, RuleDrivenPolicy>("childPolicy") .Configure <InjectedMembers>() .ConfigureInjectionFor <RuleDrivenPolicy>( "parentPolicy", new InjectionConstructor( new ResolvedArrayParameter <IMatchingRule>( new ResolvedParameter <IMatchingRule>("parentRule")), new string[] { "parentCallHandler" })) .ConfigureInjectionFor <RuleDrivenPolicy>( "childPolicy", new InjectionConstructor( new ResolvedArrayParameter <IMatchingRule>( new ResolvedParameter <IMatchingRule>("childRule")), new string[] { "childCallHandler" })) .ConfigureInjectionFor <WrappableWithProperty>( new InjectionProperty("Wrappable")) .Container .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"]); }
public void CanMixDefaultAndNonDefaultInterceptors() { IUnityContainer container = GetConfiguredContainer("CanMixDefaultAndNonDefaultInterceptors"); container .Configure <Interception>() .AddPolicy("policy") .AddMatchingRule <AlwaysMatchingRule>() .AddCallHandler <CallCountHandler>(); Wrappable anonymousWrappable = container.Resolve <Wrappable>(); Wrappable namedWrappable = container.Resolve <Wrappable>("name"); WrappableWithProperty anonymousWrappableWithProperty = container.Resolve <WrappableWithProperty>(); WrappableWithProperty namedWrappableWithProperty = container.Resolve <WrappableWithProperty>("name"); Assert.IsTrue(RemotingServices.IsTransparentProxy(anonymousWrappable)); Assert.IsTrue(RemotingServices.IsTransparentProxy(namedWrappable)); Assert.IsTrue(RemotingServices.IsTransparentProxy(anonymousWrappableWithProperty)); Assert.IsFalse(RemotingServices.IsTransparentProxy(namedWrappableWithProperty)); }