64 lines
3.7 KiB
C#
64 lines
3.7 KiB
C#
using PostFundManagement.Domain.Abstractions;
|
|
using PostFundManagement.Domain.Services;
|
|
using static PostFundManagement.Domain.Extensions.Constants;
|
|
|
|
namespace PostFundManagement.Domain.Extensions;
|
|
|
|
public static class S3
|
|
{
|
|
public static IServiceCollection AddGarageS3(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(configuration.GetSection($"{GeneralS3SettingsSection}:ServiceUrl").Value))
|
|
{
|
|
services.AddKeyedSingleton<IAmazonS3, AmazonS3Client>(GeneralBucketName, (provider, client) =>
|
|
new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{GeneralS3SettingsSection}:AccessKey").Value,
|
|
configuration.GetSection($"{GeneralS3SettingsSection}:SecretKey").Value),
|
|
new AmazonS3Config
|
|
{
|
|
ServiceURL = configuration.GetSection($"{GeneralS3SettingsSection}:ServiceUrl").Value,
|
|
AuthenticationRegion = configuration.GetSection($"{GeneralS3SettingsSection}:Region").Value,
|
|
ForcePathStyle = true,
|
|
EndpointDiscoveryEnabled = true,
|
|
UseHttp = configuration.GetSection($"{GeneralS3SettingsSection}:ServiceUrl").Value!.Contains("http://", StringComparison.InvariantCultureIgnoreCase),
|
|
}));
|
|
|
|
services.AddKeyedScoped<IS3Service, GeneralS3Service>(GeneralBucketName);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(configuration.GetSection($"{EvidenceS3SettingsSection}:ServiceUrl").Value))
|
|
{
|
|
services.AddKeyedSingleton<IAmazonS3, AmazonS3Client>(EvidenceS3SettingsSection, (provider, client) =>
|
|
new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{EvidenceS3SettingsSection}:AccessKey").Value,
|
|
configuration.GetSection($"{EvidenceS3SettingsSection}:SecretKey").Value),
|
|
new AmazonS3Config
|
|
{
|
|
ServiceURL = configuration.GetSection($"{EvidenceS3SettingsSection}:ServiceUrl").Value,
|
|
AuthenticationRegion = configuration.GetSection($"{EvidenceS3SettingsSection}:Region").Value,
|
|
ForcePathStyle = true,
|
|
EndpointDiscoveryEnabled = true,
|
|
UseHttp = configuration.GetSection($"{EvidenceS3SettingsSection}:ServiceUrl").Value!.Contains("http://", StringComparison.InvariantCultureIgnoreCase),
|
|
}));
|
|
|
|
services.AddKeyedScoped<IS3Service, EvidenceS3Service>(EvidenceS3SettingsSection);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(configuration.GetSection($"{ContractS3SettingsSection}:ServiceUrl").Value))
|
|
{
|
|
services.AddKeyedSingleton<IAmazonS3, AmazonS3Client>(ContractS3SettingsSection, (provider, client) =>
|
|
new AmazonS3Client(new BasicAWSCredentials(configuration.GetSection($"{ContractS3SettingsSection}:AccessKey").Value,
|
|
configuration.GetSection($"{ContractS3SettingsSection}:SecretKey").Value),
|
|
new AmazonS3Config
|
|
{
|
|
ServiceURL = configuration.GetSection($"{ContractS3SettingsSection}:ServiceUrl").Value,
|
|
AuthenticationRegion = configuration.GetSection($"{ContractS3SettingsSection}:Region").Value,
|
|
ForcePathStyle = true,
|
|
EndpointDiscoveryEnabled = true,
|
|
UseHttp = configuration.GetSection($"{ContractS3SettingsSection}:ServiceUrl").Value!.Contains("http://", StringComparison.InvariantCultureIgnoreCase),
|
|
}));
|
|
|
|
services.AddKeyedScoped<IS3Service, ContractS3Service>(ContractS3SettingsSection);
|
|
}
|
|
|
|
return services;
|
|
}
|
|
} |