/// <summary> /// Create a proxy wrapping specified target instance. /// </summary> /// <param name="typeToIntercept">The type to intercept.</param> /// <param name="target">The target.</param> /// <param name="interceptors">The interceptors.</param> /// <returns></returns> protected override object Wrap(Type typeToIntercept, object target, InterceptorRegistry interceptors) { var dictionary = interceptors.Interceptors .ToDictionary(it => it.Key, it => new DynamicProxyInterceptor(it.Value).ToInterceptor()); var selector = new DynamicProxyInterceptorSelector(dictionary.ToDictionary(it => it.Key, it => it.Value)); var options = new ProxyGenerationOptions { Selector = selector }; return(_proxyGenerator.CreateInterfaceProxyWithTarget(typeToIntercept, target, dictionary.Values.ToArray())); }
/// <summary> /// Create an interceptable proxy instance. /// </summary> /// <param name="typeToIntercept">The type to intercept.</param> /// <param name="serviceProvider">The <see cref="T:System.IServiceProvider" /> used to provide dependent service instances.</param> /// <param name="interceptors">The <see cref="T:Dora.DynamicProxy.InterceptorDecoration" /> representing which interceptors are applied to which members of a type to intercept.</param> /// <returns> /// The interceptable proxy instance. /// </returns> protected override object Create(Type typeToIntercept, IServiceProvider serviceProvider, InterceptorRegistry interceptors) { var dictionary = interceptors.Interceptors .ToDictionary(it => it.Key, it => new DynamicProxyInterceptor(it.Value).ToInterceptor()); var selector = new DynamicProxyInterceptorSelector(dictionary.ToDictionary(it => it.Key, it => it.Value)); var options = new ProxyGenerationOptions { Selector = selector }; return(_proxyGenerator.CreateClassProxy(typeToIntercept, options, dictionary.Values.ToArray())); }