@@ -260,11 +260,21 @@ static IAsyncPolicy<HttpResponseMessage> GetTimeoutPolicy()
260260 /// Cognite API (enabled in debug mode)</param>
261261 /// <param name="setMetrics">If true, a <see cref="IMetrics"/> metrics collector is created and used by the client
262262 /// to report metrics on the number and duration of API requests</param>
263- public static void AddCogniteClient ( this IServiceCollection services , string appId , bool setLogger = false , bool setMetrics = false )
263+ /// <param name="setHttpClient">Default true. If false <see cref="Client.Builder"/> is not added to the
264+ /// <see cref="ServiceCollection"/>. If this is false it must be added before this method is called.</param>
265+ public static void AddCogniteClient ( this IServiceCollection services ,
266+ string appId ,
267+ bool setLogger = false ,
268+ bool setMetrics = false ,
269+ bool setHttpClient = true )
264270 {
265- services . AddHttpClient < Client . Builder > ( c => c . Timeout = Timeout . InfiniteTimeSpan )
266- . AddPolicyHandler ( ( provider , message ) => { return GetRetryPolicy ( provider . GetRequiredService < ILogger < Client > > ( ) ) ; } )
267- . AddPolicyHandler ( GetTimeoutPolicy ( ) ) ;
271+ if ( setHttpClient )
272+ {
273+ services . AddHttpClient < Client . Builder > ( c => c . Timeout = Timeout . InfiniteTimeSpan )
274+ . AddPolicyHandler ( ( provider , message ) => { return GetRetryPolicy ( provider . GetRequiredService < ILogger < Client > > ( ) ) ; } )
275+ . AddPolicyHandler ( GetTimeoutPolicy ( ) ) ;
276+ }
277+
268278 services . AddHttpClient < Authenticator > ( ) ;
269279 services . AddSingleton < IMetrics , CdfMetricCollector > ( ) ;
270280 services . AddTransient ( provider => {
0 commit comments