-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDependencyInjection.cs
36 lines (30 loc) · 1.28 KB
/
DependencyInjection.cs
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
using Microsoft.Extensions.DependencyInjection;
using Refit;
using System;
namespace SuperSimpleConductor.ConductorClient
{
public static class DependencyInjection
{
/// <summary>
/// Adds the Conductor client.
/// If the Conductor api address is not specified, the worker will use
/// the environment variable CONDUCTOR_API_ADDR to connect to the Conductor api.
/// </summary>
public static IServiceCollection AddConductorClient(this IServiceCollection services, Uri? conductorApiUri = null)
{
if (conductorApiUri == null)
{
var conductorApiAddress = Environment.GetEnvironmentVariable("CONDUCTOR_API_ADDR");
if (conductorApiAddress == null)
throw new ApplicationException("No Conductor api address specified or CONDUCTOR_API_ADDR not set");
conductorApiUri = new Uri(conductorApiAddress);
}
var settings = new RefitSettings();
// Inject a custom logger so we can see the payloads sent to Conductor
settings.HttpMessageHandlerFactory = () => new HttpLoggingHandler();
services.AddRefitClient<ConductorApi>(settings)
.ConfigureHttpClient(c => c.BaseAddress = conductorApiUri);
return services;
}
}
}