Skip to content

Commit d4b01e6

Browse files
committed
Refactor IdempotencyOptions construction to use builder for configuration values
1 parent 408ddea commit d4b01e6

File tree

2 files changed

+52
-35
lines changed

2 files changed

+52
-35
lines changed

libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotencyOptions.cs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,16 @@ public class IdempotencyOptions
6767
/// <summary>
6868
/// Constructor of <see cref="IdempotencyOptions"/>.
6969
/// </summary>
70-
/// <param name="eventKeyJmesPath"></param>
71-
/// <param name="payloadValidationJmesPath"></param>
72-
/// <param name="throwOnNoIdempotencyKey"></param>
73-
/// <param name="useLocalCache"></param>
74-
/// <param name="localCacheMaxItems"></param>
75-
/// <param name="expirationInSeconds"></param>
76-
/// <param name="hashFunction"></param>
77-
/// <param name="responseHook"></param>
78-
internal IdempotencyOptions(
79-
string eventKeyJmesPath,
80-
string payloadValidationJmesPath,
81-
bool throwOnNoIdempotencyKey,
82-
bool useLocalCache,
83-
int localCacheMaxItems,
84-
long expirationInSeconds,
85-
string hashFunction,
86-
Func<object, Persistence.DataRecord, object> responseHook = null)
70+
/// <param name="builder">The builder containing the configuration values</param>
71+
internal IdempotencyOptions(IdempotencyOptionsBuilder builder)
8772
{
88-
EventKeyJmesPath = eventKeyJmesPath;
89-
PayloadValidationJmesPath = payloadValidationJmesPath;
90-
ThrowOnNoIdempotencyKey = throwOnNoIdempotencyKey;
91-
UseLocalCache = useLocalCache;
92-
LocalCacheMaxItems = localCacheMaxItems;
93-
ExpirationInSeconds = expirationInSeconds;
94-
HashFunction = hashFunction;
95-
ResponseHook = responseHook;
73+
EventKeyJmesPath = builder.EventKeyJmesPath;
74+
PayloadValidationJmesPath = builder.PayloadValidationJmesPath;
75+
ThrowOnNoIdempotencyKey = builder.ThrowOnNoIdempotencyKey;
76+
UseLocalCache = builder.UseLocalCache;
77+
LocalCacheMaxItems = builder.LocalCacheMaxItems;
78+
ExpirationInSeconds = builder.ExpirationInSeconds;
79+
HashFunction = builder.HashFunction;
80+
ResponseHook = builder.ResponseHook;
9681
}
9782
}

libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotencyOptionsBuilder.cs

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class IdempotencyOptionsBuilder
1010
/// <summary>
1111
/// Default maximum number of items in the local cache.
1212
/// </summary>
13-
private readonly int _localCacheMaxItems = 256;
13+
private int _localCacheMaxItems = 256;
1414

1515
/// <summary>
1616
/// Local cache enabled
@@ -47,6 +47,46 @@ public class IdempotencyOptionsBuilder
4747
/// </summary>
4848
private Func<object, AWS.Lambda.Powertools.Idempotency.Persistence.DataRecord, object> _responseHook;
4949

50+
/// <summary>
51+
/// Gets the event key JMESPath expression.
52+
/// </summary>
53+
internal string EventKeyJmesPath => _eventKeyJmesPath;
54+
55+
/// <summary>
56+
/// Gets the payload validation JMESPath expression.
57+
/// </summary>
58+
internal string PayloadValidationJmesPath => _payloadValidationJmesPath;
59+
60+
/// <summary>
61+
/// Gets whether to throw exception if no idempotency key is found.
62+
/// </summary>
63+
internal bool ThrowOnNoIdempotencyKey => _throwOnNoIdempotencyKey;
64+
65+
/// <summary>
66+
/// Gets whether local cache is enabled.
67+
/// </summary>
68+
internal bool UseLocalCache => _useLocalCache;
69+
70+
/// <summary>
71+
/// Gets the maximum number of items in the local cache.
72+
/// </summary>
73+
internal int LocalCacheMaxItems => _localCacheMaxItems;
74+
75+
/// <summary>
76+
/// Gets the expiration in seconds.
77+
/// </summary>
78+
internal long ExpirationInSeconds => _expirationInSeconds;
79+
80+
/// <summary>
81+
/// Gets the hash function.
82+
/// </summary>
83+
internal string HashFunction => _hashFunction;
84+
85+
/// <summary>
86+
/// Gets the response hook function.
87+
/// </summary>
88+
internal Func<object, AWS.Lambda.Powertools.Idempotency.Persistence.DataRecord, object> ResponseHook => _responseHook;
89+
5090
/// <summary>
5191
/// Initialize and return an instance of IdempotencyOptions.
5292
/// Example:
@@ -55,15 +95,7 @@ public class IdempotencyOptionsBuilder
5595
/// Idempotency.Configure(builder => builder.WithOptions(options));
5696
/// </summary>
5797
/// <returns>an instance of IdempotencyOptions</returns>
58-
public IdempotencyOptions Build() =>
59-
new(_eventKeyJmesPath,
60-
_payloadValidationJmesPath,
61-
_throwOnNoIdempotencyKey,
62-
_useLocalCache,
63-
_localCacheMaxItems,
64-
_expirationInSeconds,
65-
_hashFunction,
66-
_responseHook);
98+
public IdempotencyOptions Build() => new(this);
6799

68100
/// <summary>
69101
/// A JMESPath expression to extract the idempotency key from the event record.

0 commit comments

Comments
 (0)