@@ -0,0 +1,31 @@
|
||||
using Amazon.Runtime;
|
||||
using LiteCharms.Features.S3;
|
||||
using LiteCharms.Features.S3.Configuration;
|
||||
|
||||
namespace LiteCharms.Features.Extensions;
|
||||
|
||||
public static class S3
|
||||
{
|
||||
public static IServiceCollection AddGarageS3(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var optionsSection = configuration.GetSection(nameof(S3Settings));
|
||||
services.Configure<S3Settings>(optionsSection);
|
||||
|
||||
var options = optionsSection.Get<S3Settings>()
|
||||
?? throw new InvalidOperationException("S3 configuration section is missing.");
|
||||
|
||||
var credentials = new BasicAWSCredentials(options.AccessKey, options.SecretKey);
|
||||
|
||||
var s3Config = new AmazonS3Config
|
||||
{
|
||||
ServiceURL = options.ServiceUrl,
|
||||
AuthenticationRegion = options.Region,
|
||||
ForcePathStyle = true,
|
||||
};
|
||||
|
||||
services.AddSingleton<IAmazonS3>(new AmazonS3Client(credentials, s3Config));
|
||||
services.AddScoped<S3Service>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user