diff --git a/src/Atc.Rest.Client/Options/ServiceCollectionExtensions.cs b/src/Atc.Rest.Client/Options/ServiceCollectionExtensions.cs index 9a68bb7..be25d3e 100644 --- a/src/Atc.Rest.Client/Options/ServiceCollectionExtensions.cs +++ b/src/Atc.Rest.Client/Options/ServiceCollectionExtensions.cs @@ -7,7 +7,8 @@ public static IServiceCollection AddAtcRestClient( this IServiceCollection services, string clientName, TOptions options, - Action? httpClientBuilder = default) + Action? httpClientBuilder = default, + IContractSerializer? contractSerializer = null) where TOptions : AtcRestClientOptions, new() { services.AddSingleton(options); @@ -23,7 +24,14 @@ public static IServiceCollection AddAtcRestClient( // Register utilities services.AddSingleton(); - services.AddSingleton(); + if (contractSerializer is null) + { + services.AddSingleton(); + } + else + { + services.AddSingleton(contractSerializer); + } return services; } @@ -34,9 +42,10 @@ public static IServiceCollection AddAtcRestClient( string clientName, Uri baseAddress, TimeSpan timeout, - Action? httpClientBuilder = default) + Action? httpClientBuilder = default, + IContractSerializer? contractSerializer = null) { - var clientBuilder = services.AddHttpClient(clientName, (s, c) => + var clientBuilder = services.AddHttpClient(clientName, (_, c) => { c.BaseAddress = baseAddress; c.Timeout = timeout; @@ -46,7 +55,14 @@ public static IServiceCollection AddAtcRestClient( // Register utilities services.AddSingleton(); - services.AddSingleton(); + if (contractSerializer is null) + { + services.AddSingleton(); + } + else + { + services.AddSingleton(contractSerializer); + } return services; }