Exemplo n.º 1
0
        /// <summary>
        /// Create an instance of BetterConfigClient and setup AutoPoll mode
        /// </summary>
        /// <param name="configuration">Configuration for AutoPolling mode</param>
        /// <exception cref="ArgumentException">When the configuration contains any invalid property</exception>
        /// <exception cref="ArgumentNullException">When the configuration is null</exception>
        public BetterConfigClient(AutoPollConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            configuration.Validate();

            InitializeClient(configuration);

            var configService = new AutoPollConfigService(
                new HttpConfigFetcher(configuration.Url, "a-" + version, configuration.LoggerFactory),
                new InMemoryConfigCache(),
                TimeSpan.FromSeconds(configuration.PollIntervalSeconds),
                TimeSpan.FromSeconds(configuration.MaxInitWaitTimeSeconds),
                configuration.LoggerFactory);

            configService.OnConfigurationChanged += (sender, args) => { this.OnConfigurationChanged?.Invoke(sender, args); };

            this.configService = configService;
        }