public void can_atach_hook_as_typed_service() { var interceptor = new ResultModifierInterceptor(5); container.Register(Component.For<ResultModifierInterceptor>().Instance(interceptor), Component.For<ProxyNothingHook>(), Component.For<ICalcService>() .ImplementedBy<CalculatorService>() .Interceptors<ResultModifierInterceptor>() .Proxy.Hook(h => h.Service<ProxyNothingHook>())); var calc = container.Resolve<ICalcService>(); Assert.AreEqual(4, calc.Sum(2, 2)); }
public void hook_gets_disposed_after_proxy_is_created() { DisposableHook.InstancesCreated = 0; DisposableHook.InstancesDisposed = 0; var interceptor = new ResultModifierInterceptor(5); container.Register(Component.For<ResultModifierInterceptor>().Instance(interceptor), Component.For<DisposableHook>().Named("hook").LifeStyle.Transient, Component.For<ICalcService>() .ImplementedBy<CalculatorService>() .Interceptors<ResultModifierInterceptor>() .Proxy.Hook(h => h.Service("hook"))); container.Resolve<ICalcService>(); Assert.AreEqual(1, DisposableHook.InstancesCreated); Assert.AreEqual(1, DisposableHook.InstancesDisposed); }
public void can_atach_hook_as_instance_simple_via_nested_closure() { var interceptor = new ResultModifierInterceptor(5); var hook = new ProxyNothingHook(); Container.Register(Component.For<ResultModifierInterceptor>().Instance(interceptor), Component.For<ICalcService>() .ImplementedBy<CalculatorService>() .Interceptors<ResultModifierInterceptor>() .Proxy.Hook(h => h.Instance(hook))); var calc = Container.Resolve<ICalcService>(); Assert.AreEqual(4, calc.Sum(2, 2)); }