コード例 #1
0
 public StorageConnector(AzureBlobStorageRepositoryBuilderOptions options)
 {
     client    = new CloudBlobClient(options.Uri, options.Credentials);
     container = options.Container;
 }
コード例 #2
0
        /// <summary>
        /// Uses AzureBlobStorageRepository as IConfigRepository
        /// </summary>
        /// <param name="builder">ConfigServerBuilder to add AzureBlobStorageRepository to</param>
        /// <param name="options">Options for AzureBlobStorageRepository</param>
        /// <returns>ConfigServer builder for further configuration</returns>
        public static ConfigServerBuilder UseFileConfigProvider(this ConfigServerBuilder builder, AzureBlobStorageRepositoryBuilderOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (options.Uri == null)
            {
                throw new ArgumentException($"{nameof(options.Uri)} cannot be null", nameof(options));
            }
            if (options.Credentials == null)
            {
                throw new ArgumentException($"{nameof(options.Credentials)} cannot be null", nameof(options));
            }

            options.JsonSerializerSettings = options.JsonSerializerSettings ?? new JsonSerializerSettings();
            builder.ServiceCollection.AddMemoryCache();
            builder.ServiceCollection.Add(ServiceDescriptor.Singleton(options));
            builder.ServiceCollection.Add(ServiceDescriptor.Singleton <ITextStorageSetting>(options));
            builder.ServiceCollection.Add(ServiceDescriptor.Transient <IStorageConnector, StorageConnector>());
            builder.ServiceCollection.Add(ServiceDescriptor.Transient <IConfigRepository, TextStorageConfigurationRepository>());
            builder.ServiceCollection.Add(ServiceDescriptor.Transient <IConfigProvider, TextStorageConfigurationRepository>());
            return(builder);
        }
        /// <summary>
        /// Uses AzureBlobStorageRepository as IConfigRepository
        /// </summary>
        /// <param name="builder">ConfigServerBuilder to add AzureBlobStorageRepository to</param>
        /// <param name="options">Options for AzureBlobStorageRepository</param>
        /// <returns>ConfigServer builder for further configuration</returns>
        public static ConfigServerBuilder UseAzureBlobStorageConfigProvider(this ConfigServerBuilder builder, AzureBlobStorageRepositoryBuilderOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (options.Uri == null)
            {
                throw new ArgumentException($"{nameof(options.Uri)} cannot be null", nameof(options));
            }
            if (options.Credentials == null)
            {
                throw new ArgumentException($"{nameof(options.Credentials)} cannot be null", nameof(options));
            }

            builder.ServiceCollection.AddSingleton(options);
            builder.ServiceCollection.AddTransient <IStorageConnector, StorageConnector>();
            builder.ServiceCollection.AddTransient <IConfigRepository, TextStorageConfigurationRepository>();
            builder.ServiceCollection.AddTransient <IConfigProvider, TextStorageConfigurationRepository>();
            builder.ServiceCollection.AddTransient <IConfigClientRepository, TextStorageConfigurationClientRepository>();
            builder.ServiceCollection.AddTransient <IConfigArchive, AzureBlobStorageConfigArchive>();
            builder.ServiceCollection.AddTransient <IConfigurationSnapshotRepository, TextStorageSnapshotRepository>();
            builder.ServiceCollection.AddTransient <ISnapshotStorageConnector, AzureBlobStorageSnapshotStorageConnector>();

            return(builder);
        }