コード例 #1
0
        /// <summary>
        /// Adds the grpc client.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <param name="config">The config.</param>
        /// <returns>An IServiceCollection.</returns>
        public static IServiceCollection AddGrpcClient <T>(this IServiceCollection services, Action <PollyOption> config = null) where T : class
        {
            var type           = typeof(T);
            var memoryTypeName = type.Name.TrimEnd("Client".ToArray()) + "Base";
            var memoryType     = Type.GetType(memoryTypeName);
            var grpcService    = services.GetServiceInistaceType(memoryType);

            if (grpcService == null)
            {
                var pollyOption = new PollyOption()
                {
                    RetryCount = 3
                };
                config?.Invoke(pollyOption);
                services.AddSingleton <IRpcProxy <T> >(new Rpc <T>(new RpcPollyProxyFactory(pollyOption)));
            }
            else
            {
                services.AddSingleton <IRpcProxy <T> >(new Rpc <T>(new RpcMemoryProxyFactory(memoryType)));
            }
            return(services);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PollyInterceptor"/> class.
 /// </summary>
 /// <param name="option">The option.</param>
 public PollyInterceptor(PollyOption option)
 {
     this.option = option ??
                   throw new ArgumentNullException(nameof(option));
 }