/// <summary /> public StructureMapInterceptor() { _container = ObjectFactory.Container; var interceptorProxy = new InterceptorProxy { Container = new StructureMapServiceLocator(_container) }; _container.Configure(c => c.For<IInterceptorProxy>().Use(interceptorProxy)); }
public static object CreateProxy(Type serviceType, IInterceptor interceptor, object realInstance) { var proxy = new InterceptorProxy(serviceType, realInstance, interceptor); return(proxy.GetTransparentProxy()); }
/// <summary /> protected override void Init() { var container = new ServiceLocatorAdapter(Kernel); var proxy = new InterceptorProxy { Container = container }; Kernel.Register(Component.For(proxy.GetType()).Instance(proxy)); Kernel.ComponentRegistered += ComponentRegistered; }
/// <summary> /// Build the interceptor. /// </summary> /// <returns></returns> public T Build() { if (null == _instance) { throw new InvalidOperationException($"You must call the {nameof(For)} method and pass in a concrete instance of the interface implementation. "); } return(InterceptorProxy <T> .Create(_instance, BeforeExecutionRules, StubExecutionRules, AfterExecutionRules, _taskWaiter)); }
/// <summary /> public StructureMapInterceptor() { _container = ObjectFactory.Container; var interceptorProxy = new InterceptorProxy { Container = new StructureMapServiceLocator(_container) }; _container.Configure(c => c.For <IInterceptorProxy>().Use(interceptorProxy)); }
public InterceptorKernel(INinjectSettings settings, params INinjectModule[] modules) { var containerModules = modules == null ? new[] { _interceptor } : modules.Union(new[] { _interceptor }).ToArray(); _kernel = settings == null ? new StandardKernel(containerModules) : new StandardKernel(settings, containerModules); var proxy = new InterceptorProxy { Container = new ServiceLocatorAdapter(_kernel) }; _kernel.Bind<IInterceptorProxy>().ToConstant(proxy); }
public static void InitInterceptor(this IServiceContainer serviceContainer) { if (serviceContainer == null) { throw new ArgumentNullException("serviceContainer"); } var interceptorProxy = new InterceptorProxy {Container = new ServiceLocatorAdapter(serviceContainer)}; serviceContainer.AddService(typeof(IInterceptorProxy), interceptorProxy); serviceContainer.PostProcessors.Add(new InterceptorPostProcessor()); }
public static void InitInterceptor(this IServiceContainer serviceContainer) { if (serviceContainer == null) { throw new ArgumentNullException("serviceContainer"); } var interceptorProxy = new InterceptorProxy { Container = new ServiceLocatorAdapter(serviceContainer) }; serviceContainer.AddService(typeof(IInterceptorProxy), interceptorProxy); serviceContainer.PostProcessors.Add(new InterceptorPostProcessor()); }
public static T Create() { var interceptor = new InterceptorProxy(new T()); return((T)interceptor.GetTransparentProxy()); }
/// <summary> /// Creates an instance of <typeparamref name="TInstance"/> that will be intercepted with the specified interceptor. /// </summary> /// <typeparam name="TInstance">The type of the instance.</typeparam> /// <param name="interceptor">An interceptor instance to apply.</param> /// <param name="instance">The real instance of the type.</param> /// <returns><typeparamref name="TInstance"/> proxy instance.</returns> /// <exception cref="ArgumentNullException">The <paramref name="instance"/> is null.</exception> /// <exception cref="ArgumentNullException">The <paramref name="interceptor"/> is null.</exception> public static TInstance CreateProxy <TInstance>(IInterceptor interceptor, TInstance instance) where TInstance : class => InterceptorProxy <TInstance> .Create(instance, interceptor);