/// <summary>
        /// Registers an etcd KV Store.
        /// </summary>
        /// <param name="builder">The <see cref="IKVStoreBuilder{T}" /> to add the services to.</param>
        /// <param name="configurationSection">The <see cref="IConfigurationSection"/> which binds to <see cref="EtcdProviderOptions"/>.</param>
        /// <typeparam name="T">Generic to define type of KVStoreBuilder. </typeparam>
        /// <returns>The <see cref="IKVStoreBuilder{T}" /> so that additional calls can be chained.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static IKVStoreBuilder <T> FromEtcd <T>([NotNull] this IKVStoreBuilder <T> builder, [NotNull] IConfigurationSection configurationSection)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configurationSection?.Exists() != true)
            {
                throw new ConfigurationErrorsException($"Configuration section '{configurationSection?.Path}' is incorrect.");
            }

            var etcdProviderOptions = configurationSection.Get <EtcdProviderOptions>();

            if (etcdProviderOptions == null)
            {
                throw new ConfigurationErrorsException($"Configuration section '{configurationSection.Path}' is not valid.");
            }

            if (string.IsNullOrEmpty(etcdProviderOptions.Key))
            {
                throw new ConfigurationErrorsException($"Root key '{etcdProviderOptions.Key}' in '{configurationSection.Path}' is missing.");
            }

            builder.Services.TryAddSingleton <IDataProviderOptions <T, EtcdProviderOptions> >(new DataProviderOptions <T, EtcdProviderOptions>(etcdProviderOptions));
            builder.RegisterDataProvider <EtcdDataProvider <T> >();

            return(builder);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds Eager loading functionality for Root Key.
        /// </summary>
        /// <param name="builder">The <see cref="IKVStoreBuilder{T}" /> to add the services to.</param>
        /// <returns>The <see cref="IKVStoreBuilder{T}" /> so that additional calls can be chained.</returns>
        public static IKVStoreBuilder <T> WithEagerLoading <T>([NotNull] this IKVStoreBuilder <T> builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddHostedService <DataHostedService <T> >();

            return(builder);
        }
        /// <summary>
        /// Adds required services for Json data serialization.
        /// </summary>
        /// <param name="builder">The <see cref="IKVStoreBuilder{T}" /> to add the services to.</param>
        /// <returns>The <see cref="IKVStoreBuilder{T}" /> so that additional calls can be chained.</returns>
        public static IKVStoreBuilder <T> AddJson <T>([NotNull] this IKVStoreBuilder <T> builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddSystemTextJsonDataSerializer <T>();

            return(builder);
        }
        /// <summary>
        /// Adds required services to Memory Data Store functionality.
        /// </summary>
        /// <param name="builder">The <see cref="IKVStoreBuilder{T}" /> to add the services to.</param>
        /// <returns>The <see cref="IKVStoreBuilder{T}" /> so that additional calls can be chained.</returns>
        public static IKVStoreBuilder <T> AddMemoryDataStore <T>([NotNull] this IKVStoreBuilder <T> builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.TryAddSingleton <IDataStore <T>, MemoryDataStore <T> >();

            return(builder);
        }
Esempio n. 5
0
        /// <summary>
        /// Registers a KV Store from File.
        /// </summary>
        /// <param name="builder">The <see cref="IKVStoreBuilder{T}" /> to add the services to.</param>
        /// <param name="configuration">The <see cref="IConfiguration"/> which binds to <see cref="FileProviderOptions"/>.</param>
        /// <param name="configurationSectionName">Configuration section name. </param>
        /// <typeparam name="T">Generic to define type of KVStoreBuilder. </typeparam>
        /// <returns>The <see cref="IKVStoreBuilder{T}" /> so that additional calls can be chained.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static IKVStoreBuilder <T> FromFile <T>([NotNull] this IKVStoreBuilder <T> builder, [NotNull] IConfiguration configuration, [NotNull] string configurationSectionName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (string.IsNullOrWhiteSpace(configurationSectionName))
            {
                throw new ArgumentException($"'{nameof(configurationSectionName)}' must not be null, empty or whitespace.", nameof(configurationSectionName));
            }

            return(builder.FromFile(configuration.GetSection(configurationSectionName)));
        }
Esempio n. 6
0
        /// <summary>
        /// Registers a KV Store from File.
        /// </summary>
        /// <param name="builder">The <see cref="IKVStoreBuilder{T}" /> to add the services to.</param>
        /// <param name="configurationSection">The <see cref="IConfigurationSection"/> which binds to <see cref="FileProviderOptions"/>.</param>
        /// <typeparam name="T">Generic to define type of KVStoreBuilder. </typeparam>
        /// <returns>The <see cref="IKVStoreBuilder{T}" /> so that additional calls can be chained.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static IKVStoreBuilder <T> FromFile <T>([NotNull] this IKVStoreBuilder <T> builder, [NotNull] IConfigurationSection configurationSection)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configurationSection?.Exists() != true)
            {
                throw new ConfigurationErrorsException($"Configuration section '{configurationSection?.Path}' is incorrect.");
            }

            var fileProviderOptions = configurationSection.Get <FileProviderOptions>();

            if (fileProviderOptions == null)
            {
                throw new ConfigurationErrorsException($"Configuration section '{configurationSection.Path}' is not valid.");
            }

            builder.Services.TryAddSingleton <IDataProviderOptions <T, FileProviderOptions> >(new DataProviderOptions <T, FileProviderOptions>(fileProviderOptions));
            builder.RegisterDataProvider <FileDataProvider <T> >();

            return(builder);
        }