-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServiceExtensions.cs
More file actions
70 lines (58 loc) · 3.03 KB
/
Copy pathServiceExtensions.cs
File metadata and controls
70 lines (58 loc) · 3.03 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2025-Present Datadog, Inc.
*/
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2025 Datadog, Inc.
using Amazon.DynamoDBv2;
using Amazon.EventBridge;
using Amazon.Runtime;
using Amazon.SimpleNotificationService;
using Amazon.SQS;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Stickerlandia.PrintService.Core;
using Stickerlandia.PrintService.Core.Observability;
using Stickerlandia.PrintService.Core.Outbox;
using Stickerlandia.PrintService.Core.PrintJobs;
namespace Stickerlandia.PrintService.AWS;
public static class ServiceExtensions
{
public static IServiceCollection AddAwsAdapters(this IServiceCollection services, IConfiguration configuration,
bool enableDefaultUi = true)
{
ArgumentNullException.ThrowIfNull(configuration);
services.Configure<AwsConfiguration>(
configuration.GetSection("Aws"));
//services.AddSingleton<IMessagingWorker, SqsStickerClaimedWorker>();
services.AddSingleton<IAmazonDynamoDB>(sp =>
{
var endpointUrl = Environment.GetEnvironmentVariable("AWS_ENDPOINT_URL_DYNAMODB");
if (!string.IsNullOrEmpty(endpointUrl))
{
var credentials = new BasicAWSCredentials("dummyaccesskey", "dummysecretkey");
var config = new AmazonDynamoDBConfig { ServiceURL = endpointUrl };
return new AmazonDynamoDBClient(credentials, config);
}
return new AmazonDynamoDBClient();
});
services.AddSingleton(sp => new AmazonSQSClient());
services.AddSingleton<IAmazonEventBridge>(sp => new AmazonEventBridgeClient());
services.AddSingleton(sp => new AmazonSimpleNotificationServiceClient());
// Transaction scope and unit of work. Overrides Core's NoOpUnitOfWork via "last wins"
// DI semantics. This method MUST be called after AddStickerlandiaUserManagement().
services.AddScoped<DynamoDbWriteTransaction>();
services.AddScoped<IUnitOfWork>(sp => sp.GetRequiredService<DynamoDbWriteTransaction>());
// Repositories and outbox are Scoped to share the transaction scope
services.AddScoped<IPrinterRepository, DynamoDbPrinterRepository>();
services.AddScoped<IPrintJobRepository, DynamoDbPrintJobRepository>();
services.AddScoped<IPrinterKeyValidator, DynamoDbPrinterKeyValidator>();
services.AddScoped<IOutbox, DynamoDbOutbox>();
services.AddSingleton<IPrintServiceEventPublisher, EventBridgeEventPublisher>();
services.AddHttpClient();
services.AddSingleton<IDatadogTransactionTracker, DatadogTransactionTracker>();
return services;
}
}