Пример #1
0
        public static IServiceCollection AddCircuitBreaker(this IServiceCollection services,
                                                           CircuitBreakerOptions circuitBreakerOption,
                                                           ServiceLifetime serviceLifetime = ServiceLifetime.Scoped)
        {
            if (circuitBreakerOption is null)
            {
                throw new ArgumentNullException(nameof(circuitBreakerOption));
            }

            services.Configure <CircuitBreakerOptions>(option => option = circuitBreakerOption);

            var serviceDescriptor = new ServiceDescriptor(typeof(ICircuitBreakerFactory), typeof(CircuitBreakerFactory), serviceLifetime);

            services.Add(serviceDescriptor);

            services.AddTransient(typeof(ICircuitBreaker <>), typeof(CircuitBreaker <>));

            return(services);
        }
 public CircuitBreakerFactory(IOptions <CircuitBreakerOptions> opt)
 {
     _opt = opt.Value;
 }