using LiteCharms.Features.S3; using LiteCharms.Features.S3.Abstractions; using static LiteCharms.Features.S3.Constants; namespace LiteCharms.Features.Extensions; public static class S3 { public static IServiceCollection AddGarageS3(this IServiceCollection services, IConfiguration configuration) { if (!string.IsNullOrWhiteSpace(configuration.GetSection($"{BookshopS3SettingsSection}:ServiceUrl").Value)) { services.AddKeyedSingleton(BookshopBucketName, (provider, client) => new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{BookshopS3SettingsSection}:AccessKey").Value, configuration.GetSection($"{BookshopS3SettingsSection}:SecretKey").Value), new AmazonS3Config { ServiceURL = configuration.GetSection($"{BookshopS3SettingsSection}:ServiceUrl").Value, AuthenticationRegion = configuration.GetSection($"{BookshopS3SettingsSection}:Region").Value, ForcePathStyle = true, EndpointDiscoveryEnabled = true, UseHttp = configuration.GetSection($"{BookshopS3SettingsSection}:ServiceUrl").Value!.Contains("http://") })); services.AddKeyedScoped(BookshopBucketName); } if (!string.IsNullOrWhiteSpace(configuration.GetSection($"{BookshopInvoicesS3SettingsSection}:ServiceUrl").Value)) { services.AddKeyedSingleton(BookshopInvoicesBucketName, (provider, client) => new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{BookshopInvoicesS3SettingsSection}:AccessKey").Value, configuration.GetSection($"{BookshopInvoicesS3SettingsSection}:SecretKey").Value), new AmazonS3Config { ServiceURL = configuration.GetSection($"{BookshopInvoicesS3SettingsSection}:ServiceUrl").Value, AuthenticationRegion = configuration.GetSection($"{BookshopInvoicesS3SettingsSection}:Region").Value, ForcePathStyle = true, EndpointDiscoveryEnabled = true, UseHttp = configuration.GetSection($"{BookshopS3SettingsSection}:ServiceUrl").Value!.Contains("http://") })); services.AddKeyedScoped(BookshopInvoicesBucketName); } if (!string.IsNullOrWhiteSpace(configuration.GetSection($"{BookshopQuotesS3SettingsSection}:ServiceUrl").Value)) { services.AddKeyedSingleton(BookshopQuotesBucketName, (provider, client) => new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{BookshopQuotesS3SettingsSection}:AccessKey").Value, configuration.GetSection($"{BookshopQuotesS3SettingsSection}:SecretKey").Value), new AmazonS3Config { ServiceURL = configuration.GetSection($"{BookshopQuotesS3SettingsSection}:ServiceUrl").Value, AuthenticationRegion = configuration.GetSection($"{BookshopQuotesS3SettingsSection}:Region").Value, ForcePathStyle = true, EndpointDiscoveryEnabled = true, UseHttp = configuration.GetSection($"{BookshopS3SettingsSection}:ServiceUrl").Value!.Contains("http://") })); services.AddKeyedScoped(BookshopQuotesBucketName); } return services; } }