Esempio n. 1
0
        public void AddCircuitBreaker(IConfigurationSection configurationSection)
        {
            UraganoSettings.CircuitBreakerOptions = new CircuitBreakerOptions
            {
                Timeout = TimeSpan.FromMilliseconds(configurationSection.GetValue <int>("timeout")),
                Retry   = configurationSection.GetValue <int>("retry"),
                ExceptionsAllowedBeforeBreaking = configurationSection.GetValue <int>("ExceptionsAllowedBeforeBreaking"),
                DurationOfBreak = TimeSpan.FromMilliseconds(configurationSection.GetValue <int>("DurationOfBreak"))
            };
            var eventTypeName = configurationSection.GetValue <string>("EventHandler");

            if (!string.IsNullOrWhiteSpace(eventTypeName))
            {
                var eventType = ReflectHelper.Find(eventTypeName);
                if (eventType == null)
                {
                    throw new TypeLoadException($"Cannot load type of {eventTypeName}.");
                }
                RegisterSingletonService(typeof(ICircuitBreakerEvent), eventType);
            }
        }