Skip to content

Commit

Permalink
feat: configure default grpc calls deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Aug 14, 2024
1 parent 8881bf4 commit b88addb
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).DateTime);
}
});
});
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 b88addb

Please sign in to comment.