/// <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); }
/// <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)); }