59 lines
2.9 KiB
C#
59 lines
2.9 KiB
C#
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 (configuration.GetSection(BookshopBucketName) is not null)
|
|
{
|
|
services.AddKeyedSingleton<IAmazonS3, AmazonS3Client>(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,
|
|
}));
|
|
|
|
services.AddKeyedScoped<IS3Service, BookstoreS3Service>(BookshopBucketName);
|
|
}
|
|
|
|
if (configuration.GetSection(BookshopInvoicesBucketName) is not null)
|
|
{
|
|
services.AddKeyedSingleton<IAmazonS3, AmazonS3Client>(BookshopInvoicesBucketName, (provider, client) =>
|
|
new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{BookshopInvoicesBucketName}:AccessKey").Value,
|
|
configuration.GetSection($"{BookshopInvoicesBucketName}:SecretKey").Value),
|
|
new AmazonS3Config
|
|
{
|
|
ServiceURL = configuration.GetSection($"{BookshopInvoicesBucketName}:ServiceUrl").Value,
|
|
AuthenticationRegion = configuration.GetSection($"{BookshopInvoicesBucketName}:Region").Value,
|
|
ForcePathStyle = true,
|
|
}));
|
|
|
|
services.AddKeyedScoped<IS3Service, BookstoreInvoicesS3Service>(BookshopInvoicesBucketName);
|
|
}
|
|
|
|
if (configuration.GetSection(BookshopQuotesBucketName) is not null)
|
|
{
|
|
services.AddKeyedSingleton<IAmazonS3, AmazonS3Client>(BookshopQuotesBucketName, (provider, client) =>
|
|
new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{BookshopQuotesBucketName}:AccessKey").Value,
|
|
configuration.GetSection($"{BookshopQuotesBucketName}:SecretKey").Value),
|
|
new AmazonS3Config
|
|
{
|
|
ServiceURL = configuration.GetSection($"{BookshopQuotesBucketName}:ServiceUrl").Value,
|
|
AuthenticationRegion = configuration.GetSection($"{BookshopQuotesBucketName}:Region").Value,
|
|
ForcePathStyle = true,
|
|
}));
|
|
|
|
services.AddKeyedScoped<IS3Service, BookstoreQuotesS3Service>(BookshopQuotesBucketName);
|
|
}
|
|
|
|
return services;
|
|
}
|
|
}
|