Skip to content

Instantly share code, notes, and snippets.

@romeshniriella
Created April 1, 2019 05:09
Show Gist options
  • Save romeshniriella/aa894d0a71c9c0c3b325214d9178ebf7 to your computer and use it in GitHub Desktop.
Save romeshniriella/aa894d0a71c9c0c3b325214d9178ebf7 to your computer and use it in GitHub Desktop.
Register a Decorated HttpClient Dependency
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddAdapterApiTestClient(this IServiceCollection services, string apiUri, ConcurrentBag<DaResponse> receivedResponses)
{
services.AddHttpClient<ApiClient>(client => client.BaseAddress = new Uri(apiUri));
services
.AddSingleton<IAdapterApiClient, ApiClientSpy>(provider =>
new ApiClientSpy(provider.GetRequiredService<ApiClient>(), receivedResponses));
return services;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment