using Amazon.S3;
using Amazon.S3.Wrapper;
using Amazon.S3.Wrapper.Enums;
namespace Microsoft.Extensions.DependencyInjection
{
///
/// Configuration for S3 client
///
public static class ConfigureService
{
///
/// Register a new instance of S3Client
///
/// Collection of service descriptors
/// Configuration for AmazonS3 service
/// Bucket name
/// File content type. Default value "json"
/// S3 File storage class. Default value S3StorageClass.Standard
public static IServiceCollection RegisterIAmazonS3Client(
this IServiceCollection services,
AmazonS3Config amazonS3Config,
string bucketName,
ContentType? contentType = null,
S3StorageClass storageClass = null)
{
services.AddSingleton(_ => new AmazonS3Client(amazonS3Config));
services.AddSingleton(provider =>
{
var s3Client = provider.GetService();
return new S3Client(s3Client, bucketName, contentType, storageClass);
});
return services;
}
}
}