public void TurnProxyOnAndOff_DirectSelection() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For<WasCalledInterceptor>()).Register( Component.For(typeof(IWatcher)).ImplementedBy(typeof(BirdWatcher)).Named("bird.watcher").LifeStyle.Is( LifestyleType.Transient)); var selector = new WatcherInterceptorSelector(); container.Kernel.ProxyFactory.AddInterceptorSelector(selector); Assert.IsFalse(container.Resolve<IWatcher>().GetType().Name.Contains("Proxy")); selector.Interceptors = InterceptorKind.Dummy; Assert.IsTrue(container.Resolve<IWatcher>().GetType().Name.Contains("Proxy")); }
public void InterceptorSelectors_Are_Cumulative() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For<CountingInterceptor>(), Component.For<WasCalledInterceptor>(), Component.For<IWatcher>().ImplementedBy<BirdWatcher>().Named("bird.watcher").LifeStyle.Transient); var selector = new WatcherInterceptorSelector { Interceptors = InterceptorKind.Dummy }; container.Kernel.ProxyFactory.AddInterceptorSelector(selector); container.Kernel.ProxyFactory.AddInterceptorSelector(new AnotherInterceptorSelector()); var watcher = container.Resolve<IWatcher>(); watcher.OnSomethingInterestingToWatch += delegate { }; Assert.IsTrue(WasCalledInterceptor.WasCalled); Assert.IsTrue(WasCalledInterceptor.WasCalled); }
public void CanAddInterceptor_DirectSelection() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For<WasCalledInterceptor>(), Component.For<IWatcher>() .ImplementedBy<BirdWatcher>() .Named("bird.watcher") .LifeStyle.Transient); var selector = new WatcherInterceptorSelector(); container.Kernel.ProxyFactory.AddInterceptorSelector(selector); WasCalledInterceptor.WasCalled = false; var watcher = container.Resolve<IWatcher>(); watcher.OnSomethingInterestingToWatch += delegate { }; Assert.IsFalse(WasCalledInterceptor.WasCalled); selector.Interceptors = InterceptorKind.Dummy; WasCalledInterceptor.WasCalled = false; watcher = container.Resolve<IWatcher>(); watcher.OnSomethingInterestingToWatch += delegate { }; Assert.IsTrue(WasCalledInterceptor.WasCalled); }