Skip to content

Commit 5c177a8

Browse files
committed
refactor(approvals): Migrate DynamoDBContext initialization to builder pattern
1 parent 7121b58 commit 5c177a8

4 files changed

Lines changed: 16 additions & 12 deletions

File tree

Unicorn.Approvals/ApprovalsService/ContractStatusChangedEventHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Amazon.Lambda.Core;
1010
using Amazon.Util;
1111
using Amazon.XRay.Recorder.Handlers.AwsSdk;
12-
using DynamoDBContextConfig = Amazon.DynamoDBv2.DataModel.DynamoDBContextConfig;
1312
using AWS.Lambda.Powertools.Logging;
1413
using AWS.Lambda.Powertools.Tracing;
1514

@@ -39,8 +38,10 @@ public ContractStatusChangedEventHandler()
3938
AWSConfigsDynamoDB.Context.TypeMappings[typeof(ContractStatusChangedEvent)] =
4039
new TypeMapping(typeof(ContractStatusChangedEvent), dynamodbTable);
4140

42-
var config = new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 };
43-
_dynamoDbContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
41+
_dynamoDbContext = new DynamoDBContextBuilder()
42+
.WithDynamoDBClient(() => new AmazonDynamoDBClient())
43+
.ConfigureContext(config => config.Conversion = DynamoDBEntryConversion.V2)
44+
.Build();
4445
}
4546

4647

Unicorn.Approvals/ApprovalsService/PropertiesApprovalSyncFunction.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Amazon.StepFunctions.Model;
1212
using Amazon.Util;
1313
using Amazon.XRay.Recorder.Handlers.AwsSdk;
14-
using DynamoDBContextConfig = Amazon.DynamoDBv2.DataModel.DynamoDBContextConfig;
1514
using AWS.Lambda.Powertools.Logging;
1615
using AWS.Lambda.Powertools.Metrics;
1716
using AWS.Lambda.Powertools.Tracing;
@@ -45,8 +44,10 @@ public PropertiesApprovalSyncFunction()
4544
AWSConfigsDynamoDB.Context.TypeMappings[typeof(ContractStatusItem)] =
4645
new TypeMapping(typeof(ContractStatusItem), dynamodbTable);
4746

48-
var config = new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 };
49-
_dynamoDbContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
47+
_dynamoDbContext = new DynamoDBContextBuilder()
48+
.WithDynamoDBClient(() => new AmazonDynamoDBClient())
49+
.ConfigureContext(config => config.Conversion = DynamoDBEntryConversion.V2)
50+
.Build();
5051

5152
// Initialise Step Functions client
5253
_amazonStepFunctionsClient = new AmazonStepFunctionsClient();

Unicorn.Approvals/ApprovalsService/WaitForContractApprovalFunction.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Amazon.Lambda.Core;
99
using Amazon.Util;
1010
using Amazon.XRay.Recorder.Handlers.AwsSdk;
11-
using DynamoDBContextConfig = Amazon.DynamoDBv2.DataModel.DynamoDBContextConfig;
1211
using AWS.Lambda.Powertools.Logging;
1312
using AWS.Lambda.Powertools.Metrics;
1413
using AWS.Lambda.Powertools.Tracing;
@@ -42,8 +41,10 @@ public WaitForContractApprovalFunction()
4241
AWSConfigsDynamoDB.Context.TypeMappings[typeof(ContractStatusItem)] =
4342
new TypeMapping(typeof(ContractStatusItem), dynamodbTable);
4443

45-
var config = new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 };
46-
_dynamoDbContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
44+
_dynamoDbContext = new DynamoDBContextBuilder()
45+
.WithDynamoDBClient(() => new AmazonDynamoDBClient())
46+
.ConfigureContext(config => config.Conversion = DynamoDBEntryConversion.V2)
47+
.Build();
4748
}
4849

4950

Unicorn.Web/PublicationManagerService/RequestApprovalFunction.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using AWS.Lambda.Powertools.Metrics;
1818
using AWS.Lambda.Powertools.Tracing;
1919
using Unicorn.Web.Common;
20-
using DynamoDBContextConfig = Amazon.DynamoDBv2.DataModel.DynamoDBContextConfig;
2120

2221
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
2322
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
@@ -49,8 +48,10 @@ public RequestApprovalFunction()
4948
AWSConfigsDynamoDB.Context.TypeMappings[typeof(PropertyRecord)] =
5049
new TypeMapping(typeof(PropertyRecord), _dynamodbTable);
5150

52-
var config = new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 };
53-
_dynamoDbContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
51+
_dynamoDbContext = new DynamoDBContextBuilder()
52+
.WithDynamoDBClient(() => new AmazonDynamoDBClient())
53+
.ConfigureContext(config => config.Conversion = DynamoDBEntryConversion.V2)
54+
.Build();
5455

5556
// Initialise EventBridge client
5657
_eventBindingClient = new AmazonEventBridgeClient();

0 commit comments

Comments
 (0)