Skip to content

Commit db1f5c7

Browse files
authored
Merge pull request #47 from neuroglia-io/feat-configure-transport-http-client
feat: add extensions used to configure the underlying http client used by client transports.
2 parents 4fd3188 + 1c06eb2 commit db1f5c7

File tree

19 files changed

+65
-27
lines changed

19 files changed

+65
-27
lines changed

src/A2A.Client.Abstractions/A2A.Client.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<RootNamespace>A2A.Client</RootNamespace>
8-
<VersionPrefix>0.17.0</VersionPrefix>
8+
<VersionPrefix>0.18.0</VersionPrefix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/A2A.Client.Transports.Grpc/A2A.Client.Transports.Grpc.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<RootNamespace>A2A.Client.Transports</RootNamespace>
8-
<VersionPrefix>0.17.0</VersionPrefix>
8+
<VersionPrefix>0.18.0</VersionPrefix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/A2A.Client.Transports.Http/A2A.Client.Transports.Http.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<RootNamespace>A2A.Client.Transports</RootNamespace>
8-
<VersionPrefix>0.17.0</VersionPrefix>
8+
<VersionPrefix>0.18.0</VersionPrefix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/A2A.Client.Transports.Http/Extensions/A2AClientBuilderExtensions.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,36 @@ public static class A2AClientBuilderExtensions
2626
/// Configures the <see cref="IA2AClientBuilder"/> to use the HTTP transport.
2727
/// </summary>
2828
/// <param name="builder">The <see cref="IA2AClientBuilder"/> to configure.</param>
29-
/// <param name="baseAddress">The based address of the server to connect to.</param>
29+
/// <param name="configureClient">An <see cref="Action{T1, T2}"/> used to configure the underlying <see cref="HttpClient"/>.</param>
30+
/// <param name="configureClientBuilder"> An <see cref="Action{T}"/>, if any, used to configure the <see cref="IHttpClientBuilder"/> used to build the underlying <see cref="HttpClient"/>.</param>
3031
/// <returns>The configured <see cref="IA2AClientBuilder"/>.</returns>
31-
public static IA2AClientBuilder UseHttpTransport(this IA2AClientBuilder builder, Uri baseAddress)
32+
public static IA2AClientBuilder UseHttpTransport(this IA2AClientBuilder builder, Action<IServiceProvider, HttpClient> configureClient, Action<IHttpClientBuilder>? configureClientBuilder = null)
3233
{
33-
builder.Services.AddHttpClient<A2AHttpClientTransport>(httpClient =>
34+
var httpClientBuilder = builder.Services.AddHttpClient<IA2AClientTransport, A2AHttpClientTransport>((provider, httpClient) =>
3435
{
35-
httpClient.BaseAddress = baseAddress;
3636
httpClient.DefaultRequestHeaders.Add("A2A-Version", A2AProtocolVersion.Latest);
37+
configureClient(provider, httpClient);
3738
});
38-
builder.Services.AddSingleton<IA2AClientTransport>(provider => provider.GetRequiredService<A2AHttpClientTransport>());
39+
configureClientBuilder?.Invoke(httpClientBuilder);
3940
return builder.UseTransport<A2AHttpClientTransport>();
4041
}
4142

43+
/// <summary>
44+
/// Configures the <see cref="IA2AClientBuilder"/> to use the HTTP transport.
45+
/// </summary>
46+
/// <param name="builder">The <see cref="IA2AClientBuilder"/> to configure.</param>
47+
/// <param name="configureClient">An <see cref="Action{T}"/> used to configure the underlying <see cref="HttpClient"/>.</param>
48+
/// <param name="configureClientBuilder"> An <see cref="Action{T}"/>, if any, used to configure the <see cref="IHttpClientBuilder"/> used to build the underlying <see cref="HttpClient"/>.</param>
49+
/// <returns>The configured <see cref="IA2AClientBuilder"/>.</returns>
50+
public static IA2AClientBuilder UseHttpTransport(this IA2AClientBuilder builder, Action<HttpClient> configureClient, Action<IHttpClientBuilder>? configureClientBuilder = null) => UseHttpTransport(builder, (_, httpClient) => configureClient(httpClient), configureClientBuilder);
51+
52+
/// <summary>
53+
/// Configures the <see cref="IA2AClientBuilder"/> to use the HTTP transport.
54+
/// </summary>
55+
/// <param name="builder">The <see cref="IA2AClientBuilder"/> to configure.</param>
56+
/// <param name="baseAddress">The based address of the server to connect to.</param>
57+
/// <param name="configureClientBuilder"> An <see cref="Action{T}"/>, if any, used to configure the <see cref="IHttpClientBuilder"/> used to build the underlying <see cref="HttpClient"/>.</param>
58+
/// <returns>The configured <see cref="IA2AClientBuilder"/>.</returns>
59+
public static IA2AClientBuilder UseHttpTransport(this IA2AClientBuilder builder, Uri baseAddress, Action<IHttpClientBuilder>? configureClientBuilder = null) => UseHttpTransport(builder, httpClient => httpClient.BaseAddress = baseAddress, configureClientBuilder);
60+
4261
}

src/A2A.Client.Transports.JsonRpc/A2A.Client.Transports.JsonRpc.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<RootNamespace>A2A.Client.Transports</RootNamespace>
8-
<VersionPrefix>0.17.0</VersionPrefix>
8+
<VersionPrefix>0.18.0</VersionPrefix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/A2A.Client.Transports.JsonRpc/Extensions/A2AClientBuilderExtensions.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,36 @@ public static class A2AClientBuilderExtensions
2626
/// Configures the <see cref="IA2AClientBuilder"/> to use the JSON-RPC transport.
2727
/// </summary>
2828
/// <param name="builder">The <see cref="IA2AClientBuilder"/> to configure.</param>
29-
/// <param name="baseAddress">The based address of the server to connect to.</param>
29+
/// <param name="configureClient">An <see cref="Action{T1, T2}"/> used to configure the underlying <see cref="HttpClient"/>.</param>
30+
/// <param name="configureClientBuilder"> An <see cref="Action{T}"/>, if any, used to configure the <see cref="IHttpClientBuilder"/> used to build the underlying <see cref="HttpClient"/>.</param>
3031
/// <returns>The configured <see cref="IA2AClientBuilder"/>.</returns>
31-
public static IA2AClientBuilder UseJsonRpcTransport(this IA2AClientBuilder builder, Uri baseAddress)
32+
public static IA2AClientBuilder UseJsonRpcTransport(this IA2AClientBuilder builder, Action<IServiceProvider, HttpClient> configureClient, Action<IHttpClientBuilder>? configureClientBuilder = null)
3233
{
33-
builder.Services.AddHttpClient<A2AJsonRpcClientTransport>(httpClient =>
34+
var httpClientBuilder = builder.Services.AddHttpClient<IA2AClientTransport, A2AJsonRpcClientTransport>((provider, httpClient) =>
3435
{
35-
httpClient.BaseAddress = baseAddress;
3636
httpClient.DefaultRequestHeaders.Add("A2A-Version", A2AProtocolVersion.Latest);
37+
configureClient(provider, httpClient);
3738
});
38-
builder.Services.AddSingleton<IA2AClientTransport>(provider => provider.GetRequiredService<A2AJsonRpcClientTransport>());
39+
configureClientBuilder?.Invoke(httpClientBuilder);
3940
return builder.UseTransport<A2AJsonRpcClientTransport>();
4041
}
4142

43+
/// <summary>
44+
/// Configures the <see cref="IA2AClientBuilder"/> to use the JSON-RPC transport.
45+
/// </summary>
46+
/// <param name="builder">The <see cref="IA2AClientBuilder"/> to configure.</param>
47+
/// <param name="configureClient">An <see cref="Action{T}"/> used to configure the underlying <see cref="HttpClient"/>.</param>
48+
/// <param name="configureClientBuilder"> An <see cref="Action{T}"/>, if any, used to configure the <see cref="IHttpClientBuilder"/> used to build the underlying <see cref="HttpClient"/>.</param>
49+
/// <returns>The configured <see cref="IA2AClientBuilder"/>.</returns>
50+
public static IA2AClientBuilder UseJsonRpcTransport(this IA2AClientBuilder builder, Action<HttpClient> configureClient, Action<IHttpClientBuilder>? configureClientBuilder = null) => UseJsonRpcTransport(builder, (_, httpClient) => configureClient(httpClient), configureClientBuilder);
51+
52+
/// <summary>
53+
/// Configures the <see cref="IA2AClientBuilder"/> to use the JSON-RPC transport.
54+
/// </summary>
55+
/// <param name="builder">The <see cref="IA2AClientBuilder"/> to configure.</param>
56+
/// <param name="baseAddress">The based address of the server to connect to.</param>
57+
/// <param name="configureClientBuilder"> An <see cref="Action{T}"/>, if any, used to configure the <see cref="IHttpClientBuilder"/> used to build the underlying <see cref="HttpClient"/>.</param>
58+
/// <returns>The configured <see cref="IA2AClientBuilder"/>.</returns>
59+
public static IA2AClientBuilder UseJsonRpcTransport(this IA2AClientBuilder builder, Uri baseAddress, Action<IHttpClientBuilder>? configureClientBuilder = null) => UseJsonRpcTransport(builder, httpClient => httpClient.BaseAddress = baseAddress, configureClientBuilder);
60+
4261
}

src/A2A.Client/A2A.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<RootNamespace>A2A.Client</RootNamespace>
8-
<VersionPrefix>0.17.0</VersionPrefix>
8+
<VersionPrefix>0.18.0</VersionPrefix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/A2A.Core.JsonRpc/A2A.Core.JsonRpc.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<RootNamespace>A2A</RootNamespace>
8-
<VersionPrefix>0.17.0</VersionPrefix>
8+
<VersionPrefix>0.18.0</VersionPrefix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/A2A.Core/A2A.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<RootNamespace>A2A</RootNamespace>
8-
<VersionPrefix>0.17.0</VersionPrefix>
8+
<VersionPrefix>0.18.0</VersionPrefix>
99
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1010
<FileVersion>$(VersionPrefix)</FileVersion>
1111
<NeutralLanguage>en</NeutralLanguage>

src/A2A.Extensions.A2UI/A2A.Extensions.A2UI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<RootNamespace>A2A.Extensions</RootNamespace>
9-
<VersionPrefix>0.17.0</VersionPrefix>
9+
<VersionPrefix>0.18.0</VersionPrefix>
1010
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
1111
<FileVersion>$(VersionPrefix)</FileVersion>
1212
<NeutralLanguage>en</NeutralLanguage>

0 commit comments

Comments
 (0)