-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientsExtension.cs
More file actions
90 lines (72 loc) · 3.69 KB
/
ClientsExtension.cs
File metadata and controls
90 lines (72 loc) · 3.69 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
namespace Comanda.Orchestrator.WebApi.Extensions;
public static class ClientsExtension
{
public static void AddHttpClients(this IServiceCollection services)
{
var serviceProvider = services.BuildServiceProvider();
var settings = serviceProvider.GetRequiredService<ISettings>();
// registers the header propagation service
// essential for receiving an authenticated request and forwarding it to another service
services.AddTransient<CorrelationInterceptor>();
services.AddHeaderPropagation(options =>
{
options.Headers.Add(Headers.Authorization);
});
var customersClient = services.AddHttpClient<ICustomerClient, CustomerClient>(client =>
{
client.BaseAddress = new Uri(settings.Downstream.ProfilesUrl);
client.Timeout = TimeSpan.FromMinutes(minutes: 1, seconds: 30);
});
var ownersClient = services.AddHttpClient<IOwnerClient, OwnerClient>(client =>
{
client.BaseAddress = new Uri(settings.Downstream.ProfilesUrl);
client.Timeout = TimeSpan.FromMinutes(minutes: 1, seconds: 30);
});
var paymentsClient = services.AddHttpClient<IPaymentClient, PaymentClient>(client =>
{
client.BaseAddress = new Uri(settings.Downstream.PaymentsUrl);
client.Timeout = TimeSpan.FromMinutes(minutes: 1, seconds: 30);
});
var storesClient = services.AddHttpClient<IEstablishmentClient, EstablishmentClient>(client =>
{
client.BaseAddress = new Uri(settings.Downstream.StoresUrl);
client.Timeout = TimeSpan.FromMinutes(minutes: 1, seconds: 30);
});
var productsClient = services.AddHttpClient<IProductClient, ProductClient>(client =>
{
client.BaseAddress = new Uri(settings.Downstream.StoresUrl);
client.Timeout = TimeSpan.FromMinutes(minutes: 1, seconds: 30);
});
var credentialsClient = services.AddHttpClient<ICredentialsClient, CredentialsClient>(client =>
{
client.BaseAddress = new Uri(settings.Downstream.StoresUrl);
client.Timeout = TimeSpan.FromMinutes(minutes: 1, seconds: 30);
});
var subscriptionsClient = services.AddHttpClient<ISubscriptionClient, SubscriptionClient>(client =>
{
client.BaseAddress = new Uri(settings.Downstream.SubscriptionsUrl);
client.Timeout = TimeSpan.FromMinutes(minutes: 1, seconds: 30);
});
var ordersClient = services.AddHttpClient<IOrderClient, OrderClient>(client =>
{
client.BaseAddress = new Uri(settings.Downstream.OrdersUrl);
client.Timeout = TimeSpan.FromMinutes(minutes: 1, seconds: 30);
});
customersClient.AddHeaderPropagation();
customersClient.AddHttpMessageHandler<CorrelationInterceptor>();
ownersClient.AddHeaderPropagation();
ownersClient.AddHttpMessageHandler<CorrelationInterceptor>();
paymentsClient.AddHeaderPropagation();
paymentsClient.AddHttpMessageHandler<CorrelationInterceptor>();
storesClient.AddHeaderPropagation();
storesClient.AddHttpMessageHandler<CorrelationInterceptor>();
productsClient.AddHeaderPropagation();
productsClient.AddHttpMessageHandler<CorrelationInterceptor>();
subscriptionsClient.AddHeaderPropagation();
subscriptionsClient.AddHttpMessageHandler<CorrelationInterceptor>();
ordersClient.AddHeaderPropagation();
ordersClient.AddHttpMessageHandler<CorrelationInterceptor>();
credentialsClient.AddHeaderPropagation();
credentialsClient.AddHttpMessageHandler<CorrelationInterceptor>();
}
}