/// <summary> /// Adds <see cref="IFileService"/> using Azure Blob Storage as the backing store. /// </summary> /// <param name="services">Specifies the contract for a collection of service descriptors.</param> /// <param name="configure">Configure the available options. Null to use defaults.</param> public static IServiceCollection AddFilesAzure(this IServiceCollection services, Action <FileServiceAzureStorage.FileServiceOptions> configure = null) { services.AddTransient <IFileService, FileServiceAzureStorage>(serviceProvider => { var options = new FileServiceAzureStorage.FileServiceOptions { ConnectionString = serviceProvider.GetRequiredService <IConfiguration>().GetConnectionString(FileServiceAzureStorage.CONNECTION_STRING_NAME), EnvironmentName = serviceProvider.GetRequiredService <IWebHostEnvironment>().EnvironmentName }; configure?.Invoke(options); return(new FileServiceAzureStorage(options.ConnectionString, options.EnvironmentName)); }); return(services); }
/// <summary> /// Adds <see cref="FileServiceAzureStorage"/> implementation. /// </summary> public static FileServiceConfigurationBuilder AddAzureStorage(this FileServiceConfigurationBuilder builder, string name, Action <FileServiceAzureStorage.FileServiceOptions> configure = null) { builder.Services.AddKeyedService <IFileService, FileServiceAzureStorage, string>( key: name, serviceProvider => { var options = new FileServiceAzureStorage.FileServiceOptions { ConnectionStringName = FileServiceAzureStorage.CONNECTION_STRING_NAME, ContainerName = serviceProvider.GetRequiredService <IHostEnvironment>().EnvironmentName }; configure?.Invoke(options); var connectionString = serviceProvider.GetRequiredService <IConfiguration>().GetConnectionString(options.ConnectionStringName); return(new FileServiceAzureStorage(connectionString, options.ContainerName)); }, serviceLifetime: ServiceLifetime.Transient ); return(builder); }