Skip to content

Commit

Permalink
Update Named Client
Browse files Browse the repository at this point in the history
  • Loading branch information
Peymanpn committed Jul 19, 2023
1 parent 56103d4 commit 37bcca1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.200",
"version": "7.0.306",
"allowPrerelease": false,
"rollForward": "latestFeature"
}
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.7.0-preview.1</Version>
<Version>3.7.0</Version>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
4 changes: 2 additions & 2 deletions src/Pdsr.Http/Pdsr.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
</ItemGroup>

</Project>
30 changes: 0 additions & 30 deletions src/Pdsr.Http/PdsrClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,33 +355,3 @@ public virtual void Log(LogLevel logLevel, string message, params object[] args)
_logger.Log(logLevel, message, args);
}
}


/// <summary>
/// Abstraction of <see cref="PdsrClientBase"/> with named clients
/// </summary>
/// <typeparam name="TConfig"><see cref="IPdsrClientConfigs"/> type for client configurations</typeparam>
public abstract class PdsrNamedClientBase<TConfig> : PdsrClientBase
where TConfig : IPdsrClientConfigs
{
/// <inheritdoc/>
protected PdsrNamedClientBase(HttpClient client, ILoggerFactory loggerFactory)
: base(client, loggerFactory)
{
}


/// <summary>
/// Using <see cref="IHttpClientFactory"/> instead of using unnamed <see cref="HttpClient" />
/// To Use the named client, the type <see cref="PdsrClientConfigs"/> must be injected to DI
/// and <see cref="PdsrClientConfigs.ClientName"/> must be initialized.
/// </summary>
/// <param name="httpClientFactory">Client Factory, with named clients</param>
/// <param name="loggerFactory">Instance of Logger factory</param>
/// <param name="clientConfigs">PdsrClientConfigurations, must be injected to the DI if you plan to use named clients</param>
public PdsrNamedClientBase(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, TConfig clientConfigs)
: base(httpClientFactory.CreateClient(clientConfigs.ClientName), loggerFactory)
{
}

}
32 changes: 32 additions & 0 deletions src/Pdsr.Http/PdsrNamedClientBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.Extensions.Logging;

namespace Pdsr.Http;

/// <summary>
/// Abstraction of <see cref="PdsrClientBase"/> with named clients
/// </summary>
/// <typeparam name="TConfig"><see cref="IPdsrClientConfigs"/> type for client configurations</typeparam>
public abstract class PdsrNamedClientBase<TConfig> : PdsrClientBase
where TConfig : IPdsrClientConfigs
{
/// <inheritdoc/>
protected PdsrNamedClientBase(HttpClient client, ILoggerFactory loggerFactory)
: base(client, loggerFactory)
{
}


/// <summary>
/// Using <see cref="IHttpClientFactory"/> instead of using unnamed <see cref="HttpClient" />
/// To Use the named client, the type <see cref="PdsrClientConfigs"/> must be injected to DI
/// and <see cref="PdsrClientConfigs.ClientName"/> must be initialized.
/// </summary>
/// <param name="httpClientFactory">Client Factory, with named clients</param>
/// <param name="loggerFactory">Instance of Logger factory</param>
/// <param name="clientConfigs">PdsrClientConfigurations, must be injected to the DI if you plan to use named clients</param>
public PdsrNamedClientBase(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, TConfig clientConfigs)
: base(httpClientFactory.CreateClient(clientConfigs.ClientName), loggerFactory)
{
}

}

0 comments on commit 37bcca1

Please sign in to comment.