Skip to content

Commit

Permalink
Merge pull request #31 from atc-net/feature/IContractSerializer-overl…
Browse files Browse the repository at this point in the history
…oad-parameter

Add IContractSerializer overload parameter
  • Loading branch information
davidkallesen authored Jul 14, 2024
2 parents 936882c + 656980d commit bd538f2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
<ItemGroup Label="Code Analyzers">
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
<PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.159" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.160" PrivateAssets="All" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.28.0.94264" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.29.0.95321" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Atc.Rest.Client/Atc.Rest.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
Expand Down
26 changes: 21 additions & 5 deletions src/Atc.Rest.Client/Options/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public static IServiceCollection AddAtcRestClient<TOptions>(
this IServiceCollection services,
string clientName,
TOptions options,
Action<IHttpClientBuilder>? httpClientBuilder = default)
Action<IHttpClientBuilder>? httpClientBuilder = default,
IContractSerializer? contractSerializer = null)
where TOptions : AtcRestClientOptions, new()
{
services.AddSingleton(options);
Expand All @@ -23,7 +24,14 @@ public static IServiceCollection AddAtcRestClient<TOptions>(

// Register utilities
services.AddSingleton<IHttpMessageFactory, HttpMessageFactory>();
services.AddSingleton<IContractSerializer, DefaultJsonContractSerializer>();
if (contractSerializer is null)
{
services.AddSingleton<IContractSerializer, DefaultJsonContractSerializer>();
}
else
{
services.AddSingleton(contractSerializer);
}

return services;
}
Expand All @@ -34,9 +42,10 @@ public static IServiceCollection AddAtcRestClient(
string clientName,
Uri baseAddress,
TimeSpan timeout,
Action<IHttpClientBuilder>? httpClientBuilder = default)
Action<IHttpClientBuilder>? httpClientBuilder = default,
IContractSerializer? contractSerializer = null)
{
var clientBuilder = services.AddHttpClient(clientName, (s, c) =>
var clientBuilder = services.AddHttpClient(clientName, (_, c) =>
{
c.BaseAddress = baseAddress;
c.Timeout = timeout;
Expand All @@ -46,7 +55,14 @@ public static IServiceCollection AddAtcRestClient(

// Register utilities
services.AddSingleton<IHttpMessageFactory, HttpMessageFactory>();
services.AddSingleton<IContractSerializer, DefaultJsonContractSerializer>();
if (contractSerializer is null)
{
services.AddSingleton<IContractSerializer, DefaultJsonContractSerializer>();
}
else
{
services.AddSingleton(contractSerializer);
}

return services;
}
Expand Down
4 changes: 2 additions & 2 deletions test/Atc.Rest.Client.Tests/Atc.Rest.Client.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit bd538f2

Please sign in to comment.