Пример #1
0
        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 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 calculator = Container.Resolve <ICalcService>();

            AssertIsProxy(calculator);
            Assert.AreEqual(4, calculator.Sum(2, 2));
        }
Пример #3
0
        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 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_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));
		}