diff --git a/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs b/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs index 449e73ad2..90d8b43de 100644 --- a/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs +++ b/src/Sitko.Core.Grpc.Client/GrpcClientModule.cs @@ -26,10 +26,22 @@ public override void ConfigureServices(IApplicationContext applicationContext, I "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); } + services.TryAddSingleton(TimeProvider.System); services.TryAddSingleton>(); services.TryAddSingleton(); services.TryAddTransient(); - var builder = services.AddGrpcClient(); + var builder = services.AddGrpcClient((provider, options) => + { + options.CallOptionsActions.Add(context => + { + if (startupOptions.DefaultDeadline is not null) + { + context.CallOptions = context.CallOptions.WithDeadline(provider.GetRequiredService() + .GetUtcNow() + .Add(startupOptions.DefaultDeadline.Value).UtcDateTime); + } + }); + }); services.AddTransient, GrpcClientProvider>(); RegisterResolver(services, startupOptions); startupOptions.ConfigureClient(services, builder); diff --git a/src/Sitko.Core.Grpc.Client/GrpcClientModuleOptions.cs b/src/Sitko.Core.Grpc.Client/GrpcClientModuleOptions.cs index 5116b4b76..af6e7abe1 100644 --- a/src/Sitko.Core.Grpc.Client/GrpcClientModuleOptions.cs +++ b/src/Sitko.Core.Grpc.Client/GrpcClientModuleOptions.cs @@ -17,6 +17,7 @@ public class GrpcClientModuleOptions : BaseModuleOptions where TClient private readonly List> configureServicesActions = new(); public bool EnableHttp2UnencryptedSupport { get; set; } public bool DisableCertificatesValidation { get; set; } + public TimeSpan? DefaultDeadline { get; set; } = TimeSpan.FromMinutes(30); [JsonIgnore] public Action? ConfigureChannelOptions { get; set; } [JsonIgnore] public Func? ConfigureHttpHandler { get; set; }