Skip to content

Commit

Permalink
Merge pull request #1009 from sitkoru/grpc/client/deadlines
Browse files Browse the repository at this point in the history
Grpc/client/deadlines
  • Loading branch information
pogromistik authored Aug 15, 2024
2 parents 8881bf4 + 821da4d commit 28ad3e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Sitko.Core.Grpc.Client/GrpcClientModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@ public override void ConfigureServices(IApplicationContext applicationContext, I
"System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
}

services.TryAddSingleton(TimeProvider.System);
services.TryAddSingleton<GrpcClientActivator<TClient>>();
services.TryAddSingleton<GrpcCallInvokerFactory>();
services.TryAddTransient<global::Grpc.Net.ClientFactory.GrpcClientFactory, GrpcClientFactory>();
var builder = services.AddGrpcClient<TClient>();
var builder = services.AddGrpcClient<TClient>((provider, options) =>
{
options.CallOptionsActions.Add(context =>
{
if (startupOptions.DefaultDeadline is not null)
{
context.CallOptions = context.CallOptions.WithDeadline(provider.GetRequiredService<TimeProvider>()
.GetUtcNow()
.Add(startupOptions.DefaultDeadline.Value).UtcDateTime);
}
});
});
services.AddTransient<IGrpcClientProvider<TClient>, GrpcClientProvider<TClient>>();
RegisterResolver(services, startupOptions);
startupOptions.ConfigureClient(services, builder);
Expand Down
1 change: 1 addition & 0 deletions src/Sitko.Core.Grpc.Client/GrpcClientModuleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class GrpcClientModuleOptions<TClient> : BaseModuleOptions where TClient
private readonly List<Action<IServiceCollection>> configureServicesActions = new();
public bool EnableHttp2UnencryptedSupport { get; set; }
public bool DisableCertificatesValidation { get; set; }
public TimeSpan? DefaultDeadline { get; set; } = TimeSpan.FromMinutes(30);
[JsonIgnore] public Action<GrpcChannelOptions>? ConfigureChannelOptions { get; set; }
[JsonIgnore] public Func<HttpClientHandler, HttpMessageHandler>? ConfigureHttpHandler { get; set; }

Expand Down

0 comments on commit 28ad3e3

Please sign in to comment.