Пример #1
0
        /// <summary>
        /// Creates a proxy of a given class/interface instance so the virtual calls can be intercepted and made using a Polly policy.
        /// </summary>
        /// <param name="instance">The instance to proxy</param>
        /// <param name="config">The configuration for this instance.</param>
        /// <returns>The proxied instance of T</returns>
        public static T Create(T instance, Action <IProxyConfig <T> > config)
        {
            var cfg = new ProxyConfig <T>();

            config.Invoke(cfg);
            var interceptor = new PollyProxyInterceptorAsync <T>(cfg);

            if (typeof(T).GetTypeInfo().IsInterface)
            {
                return(Generator.CreateInterfaceProxyWithTarget <T>(instance, new[] { interceptor }));
            }
            else
            {
                return(Generator.CreateClassProxyWithTarget <T>(instance, new[] { interceptor }));
            }
        }
 public PollyProxyInterceptorAsync(ProxyConfig <T> config)
 {
     _config = config;
 }