@@ -7,7 +7,8 @@ public static IServiceCollection AddAtcRestClient<TOptions>(
7
7
this IServiceCollection services ,
8
8
string clientName ,
9
9
TOptions options ,
10
- Action < IHttpClientBuilder > ? httpClientBuilder = default )
10
+ Action < IHttpClientBuilder > ? httpClientBuilder = default ,
11
+ IContractSerializer ? contractSerializer = null )
11
12
where TOptions : AtcRestClientOptions , new ( )
12
13
{
13
14
services . AddSingleton ( options ) ;
@@ -23,7 +24,14 @@ public static IServiceCollection AddAtcRestClient<TOptions>(
23
24
24
25
// Register utilities
25
26
services . AddSingleton < IHttpMessageFactory , HttpMessageFactory > ( ) ;
26
- services . AddSingleton < IContractSerializer , DefaultJsonContractSerializer > ( ) ;
27
+ if ( contractSerializer is null )
28
+ {
29
+ services . AddSingleton < IContractSerializer , DefaultJsonContractSerializer > ( ) ;
30
+ }
31
+ else
32
+ {
33
+ services . AddSingleton ( contractSerializer ) ;
34
+ }
27
35
28
36
return services ;
29
37
}
@@ -34,9 +42,10 @@ public static IServiceCollection AddAtcRestClient(
34
42
string clientName ,
35
43
Uri baseAddress ,
36
44
TimeSpan timeout ,
37
- Action < IHttpClientBuilder > ? httpClientBuilder = default )
45
+ Action < IHttpClientBuilder > ? httpClientBuilder = default ,
46
+ IContractSerializer ? contractSerializer = null )
38
47
{
39
- var clientBuilder = services . AddHttpClient ( clientName , ( s , c ) =>
48
+ var clientBuilder = services . AddHttpClient ( clientName , ( _ , c ) =>
40
49
{
41
50
c . BaseAddress = baseAddress ;
42
51
c . Timeout = timeout ;
@@ -46,7 +55,14 @@ public static IServiceCollection AddAtcRestClient(
46
55
47
56
// Register utilities
48
57
services . AddSingleton < IHttpMessageFactory , HttpMessageFactory > ( ) ;
49
- services . AddSingleton < IContractSerializer , DefaultJsonContractSerializer > ( ) ;
58
+ if ( contractSerializer is null )
59
+ {
60
+ services . AddSingleton < IContractSerializer , DefaultJsonContractSerializer > ( ) ;
61
+ }
62
+ else
63
+ {
64
+ services . AddSingleton ( contractSerializer ) ;
65
+ }
50
66
51
67
return services ;
52
68
}
0 commit comments