Beispiel #1
0
 /// <summary>
 /// See the <see cref="IProxyGenerator.CreateInterfaceProxyWithTarget{TInterface}(TInterface,IInterceptor[])"/> documentation.
 /// </summary>
 public static TInterface CreateInterfaceProxyWithTarget <TInterface>(
     this IProxyGenerator proxyGenerator,
     TInterface target,
     params IAsyncInterceptor[] interceptors)
     where TInterface : class
 {
     return(proxyGenerator.CreateInterfaceProxyWithTarget(target, interceptors.ToInterceptors()));
 }
        public static T CreateProxyWithAspects <T>(this IProxyGenerator proxyGenerator, T original, params IAspect[] aspects)
            where T : class
        {
            var interceptor = new AspectInterceptor(aspects.Flatten());
            var proxy       = proxyGenerator.CreateInterfaceProxyWithTarget <T>(original, interceptor);

            return(proxy);
        }
Beispiel #3
0
 /// <summary>
 /// See the <see cref="IProxyGenerator.CreateInterfaceProxyWithTarget(Type, object, IInterceptor[])"/> documentation.
 /// </summary>
 public static object CreateInterfaceProxyWithTarget(
     this IProxyGenerator proxyGenerator,
     Type interfaceToProxy,
     object target,
     params IAsyncInterceptor[] interceptors)
 {
     return(proxyGenerator.CreateInterfaceProxyWithTarget(
                interfaceToProxy,
                target,
                interceptors.ToInterceptors()));
 }
Beispiel #4
0
        public T CreateProxy(T instance)
        {
            var coreInterceptor = new CoreInterceptor(_serviceProvider, _configuration);
            var proxy           = _proxyGenerator.CreateInterfaceProxyWithTarget(typeof(T), instance, coreInterceptor);

            if (proxy == null)
            {
                throw new ArgumentNullException(nameof(proxy));
            }

            return((T)proxy);
        }
Beispiel #5
0
        public object CreateProxy(Type serviceType, object target)
        {
            var interceptor = new CoreInterceptor(serviceProvider, proxyConfig);
            var proxy       = proxyGenerator.CreateInterfaceProxyWithTarget(serviceType, target, interceptor);

            if (proxy == null)
            {
                throw new ArgumentNullException(nameof(proxy));
            }

            return(proxy);
        }
Beispiel #6
0
 /// <summary>
 /// See the <see cref="IProxyGenerator .CreateInterfaceProxyWithTarget(Type, Type[], object, ProxyGenerationOptions, IInterceptor[])"/> documentation.
 /// </summary>
 public static object CreateInterfaceProxyWithTarget(
     this IProxyGenerator proxyGenerator,
     Type interfaceToProxy,
     Type[] additionalInterfacesToProxy,
     object target,
     ProxyGenerationOptions options,
     params IAsyncInterceptor[] interceptors)
 {
     return(proxyGenerator.CreateInterfaceProxyWithTarget(
                interfaceToProxy,
                additionalInterfacesToProxy,
                target,
                options,
                interceptors.ToInterceptors()));
 }
Beispiel #7
0
        /// <summary>
        /// Create a proxy wrapping specified target instance and interceptors.
        /// </summary>
        /// <param name="typeToProxy">The declaration type of proxy to create.</param>
        /// <param name="target">The target instance wrapped by the created proxy.</param>
        /// <param name="initerceptors">The interceptors specific to each methods.</param>
        /// <returns>The proxy wrapping the specified target instance.</returns>
        /// <exception cref="ArgumentNullException">The argument <paramref name="typeToProxy"/> is null.</exception>
        /// <exception cref="ArgumentNullException">The argument <paramref name="target"/> is null.</exception>
        /// <exception cref="ArgumentNullException">The argument <paramref name="initerceptors"/> is null.</exception>
        protected object CreateProxyCore(Type typeToProxy, object target, IDictionary <MethodInfo, InterceptorDelegate> initerceptors)
        {
            if (!initerceptors.Any())
            {
                return(target);
            }
            IDictionary <MethodInfo, IInterceptor> dic = initerceptors.ToDictionary(it => it.Key, it => (IInterceptor) new DynamicProxyInterceptor(it.Value));
            var selector = new DynamicProxyInterceptorSelector(dic);
            var options  = new ProxyGenerationOptions {
                Selector = selector
            };

            if (typeToProxy.GetTypeInfo().IsInterface)
            {
                return(_proxyGenerator.CreateInterfaceProxyWithTarget(typeToProxy, target, options, dic.Values.ToArray()));
            }
            else
            {
                return(_proxyGenerator.CreateClassProxyWithTarget(typeToProxy, target, options, dic.Values.ToArray()));
            }
        }
 private static object CreateProxyWithTarget(
     Type serviceType,
     object target,
     ProxyGenerationOptions proxyGenerationOptions,
     IInterceptor[] interceptors)
 {
     if (serviceType.IsInterface)
     {
         return(ProxyGenerator.CreateInterfaceProxyWithTarget(
                    serviceType,
                    target,
                    proxyGenerationOptions,
                    interceptors));
     }
     else
     {
         return(ProxyGenerator.CreateClassProxyWithTarget(
                    serviceType,
                    target,
                    proxyGenerationOptions,
                    interceptors));
     }
 }
Beispiel #9
0
 public void SetProxy(TChart chart)
 {
     Chart = generator.CreateInterfaceProxyWithTarget(chart, interceptor);
     Proxy = true;
 }
 public HomeController(IProxyGenerator generator, IFibonacciEvaluator fibonacciEvaluator, IInterceptor interceptor)
 {
     this._fibonacciEvaluator = generator.CreateInterfaceProxyWithTarget(fibonacciEvaluator, interceptor);
 }
Beispiel #11
0
        public T CreateInterface <T>(T real, IInterceptor[] interceptors) where T : class
        {
            var proxy = _generator.CreateInterfaceProxyWithTarget(real, ProxyGenerationOptions.Default, interceptors);

            return(proxy);
        }