Skip to content

Commit

Permalink
Option to not set http client in AddCogniteClient
Browse files Browse the repository at this point in the history
  • Loading branch information
einarmo committed Jun 10, 2020
1 parent 7edc0c5 commit 0d95454
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ExtractorUtils/Cognite/CogniteUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,21 @@ static IAsyncPolicy<HttpResponseMessage> GetTimeoutPolicy()
/// Cognite API (enabled in debug mode)</param>
/// <param name="setMetrics">If true, a <see cref="IMetrics"/> metrics collector is created and used by the client
/// to report metrics on the number and duration of API requests</param>
public static void AddCogniteClient(this IServiceCollection services, string appId, bool setLogger = false, bool setMetrics = false)
/// <param name="setHttpClient">Default true. If false <see cref="Client.Builder"/> is not added to the
/// <see cref="ServiceCollection"/>. If this is false it must be added before this method is called.</param>
public static void AddCogniteClient(this IServiceCollection services,
string appId,
bool setLogger = false,
bool setMetrics = false,
bool setHttpClient = true)
{
services.AddHttpClient<Client.Builder>(c => c.Timeout = Timeout.InfiniteTimeSpan)
.AddPolicyHandler((provider, message) => { return GetRetryPolicy(provider.GetRequiredService<ILogger<Client>>()); })
.AddPolicyHandler(GetTimeoutPolicy());
if (setHttpClient)
{
services.AddHttpClient<Client.Builder>(c => c.Timeout = Timeout.InfiniteTimeSpan)
.AddPolicyHandler((provider, message) => { return GetRetryPolicy(provider.GetRequiredService<ILogger<Client>>()); })
.AddPolicyHandler(GetTimeoutPolicy());
}

services.AddHttpClient<Authenticator>();
services.AddSingleton<IMetrics, CdfMetricCollector>();
services.AddTransient(provider => {
Expand Down

0 comments on commit 0d95454

Please sign in to comment.