-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathAmazonS3BucketClient.cs
More file actions
56 lines (49 loc) · 1.85 KB
/
AmazonS3BucketClient.cs
File metadata and controls
56 lines (49 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using Amazon.S3;
namespace SixLabors.ImageSharp.Web.AWS;
/// <summary>
/// Represents a scoped Amazon S3 client instance that is explicitly associated with a single S3 bucket.
/// This wrapper provides a strongly-typed link between the client and the bucket it operates on,
/// and optionally manages the lifetime of the underlying <see cref="AmazonS3Client"/>.
/// </summary>
public sealed class AmazonS3BucketClient : IDisposable
{
private readonly bool disposeClient;
/// <summary>
/// Initializes a new instance of the <see cref="AmazonS3BucketClient"/> class.
/// </summary>
/// <param name="bucketName">
/// The bucket name associated with this client instance.
/// </param>
/// <param name="client">
/// The underlying Amazon S3 client instance. This should be an already configured instance of <see cref="AmazonS3Client"/>.
/// </param>
/// <param name="disposeClient">
/// A value indicating whether the underlying client should be disposed when this instance is disposed.
/// </param>
public AmazonS3BucketClient(string bucketName, AmazonS3Client client, bool disposeClient = true)
{
Guard.NotNullOrWhiteSpace(bucketName, nameof(bucketName));
Guard.NotNull(client, nameof(client));
this.BucketName = bucketName;
this.Client = client;
this.disposeClient = disposeClient;
}
/// <summary>
/// Gets the bucket name associated with this client instance.
/// </summary>
public string BucketName { get; }
/// <summary>
/// Gets the underlying Amazon S3 client instance.
/// </summary>
public AmazonS3Client Client { get; }
/// <inheritdoc/>
public void Dispose()
{
if (this.disposeClient)
{
this.Client.Dispose();
}
}
}