Grpc.Net.ClientFactory 2.66.0

Grpc.Net.ClientFactory

gRPC integration with HttpClientFactory offers a centralized way to create gRPC clients. It can be used as an alternative to configuring stand-alone gRPC client instances.

The factory offers the following benefits:

  • Provides a central location for configuring logical gRPC client instances
  • Manages the lifetime of the underlying HttpClientMessageHandler
  • Automatic propagation of deadline and cancellation in an ASP.NET Core gRPC service

Register gRPC clients

To register a gRPC client, the generic AddGrpcClient extension method can be used within Startup.ConfigureServices, specifying the gRPC typed client class and service address:

services.AddGrpcClient<Greeter.GreeterClient>(o =>
{
    o.Address = new Uri("https://localhost:5001");
});

The gRPC client type is registered as transient with dependency injection (DI). The client can now be injected and consumed directly in types created by DI. ASP.NET Core MVC controllers, SignalR hubs and gRPC services are places where gRPC clients can automatically be injected:

public class AggregatorService : Aggregator.AggregatorBase
{
    private readonly Greeter.GreeterClient _client;

    public AggregatorService(Greeter.GreeterClient client)
    {
        _client = client;
    }

    public override async Task SayHellos(HelloRequest request,
        IServerStreamWriter<HelloReply> responseStream, ServerCallContext context)
    {
        // Forward the call on to the greeter service
        using (var call = _client.SayHellos(request))
        {
            await foreach (var response in call.ResponseStream.ReadAllAsync())
            {
                await responseStream.WriteAsync(response);
            }
        }
    }
}

Showing the top 20 packages that depend on Grpc.Net.ClientFactory.

Packages Downloads
KitSys.Common.Protos.DTO
KitSys.Common.Protos.DTO
4,620
SanedBuildingBlocks
This package built for OIG-Saned
3,442
SanedBuildingBlocks
This package built for OIG-Saned
2,443
KitSys.Delivery.Protos.Client
KitSys.Delivery.Protos.Client
1,692
KitSys.DataImporter.Protos.Client
KitSys.DataImporter.Protos.Client
1,686
KitSys.ClinicSystem.Protos.Client
KitSys.ClinicSystem.Protos.Client
1,683
KitSys.KitsysFileware.Protos.Client
KitSys.KitsysFileware.Protos.Client
1,680
KitSys.KitsysFinance.Protos.Client
KitSys.KitsysFinance.Protos.Client
1,636
KitSys.SuppliersCustomersPortal.Protos.Client
KitSys.SuppliersCustomersPortal.Protos.Client
1,631
KitSys.FinancialStatement.Protos.Client
KitSys.FinancialStatement.Protos.Client
1,614
KitSys.Anhar.Protos.Client
KitSys.Anhar.Protos.Client
1,606
KitSys.AccountPayable.Protos.Client
KitSys.AccountPayable.Protos.Client
1,606
KitSys.MailService.Protos.Client
KitSys.MailService.Protos.Client
1,602
KitSys.NotificationManager.Protos.Client
KitSys.NotificationManager.Protos.Client
1,585
KitSys.SanedTemps.Protos.Client
KitSys.SanedTemps.Protos.Client
1,582
KitSys.SanedServices.Protos.Client
KitSys.SanedServices.Protos.Client
1,565
KitSys.NotificationService.Protos.Client
KitSys.NotificationService.Protos.Client
1,555
KitSys.SanedFinancialTransaction.Protos.Client
KitSys.SanedFinancialTransaction.Protos.Client
1,555
KitSys.SuccessionManagement.Protos.Client
KitSys.SuccessionManagement.Protos.Client
1,525
KitSys.SanedModuleBuilder.Protos.Client
KitSys.SanedModuleBuilder.Protos.Client
1,522

.NET 6.0

.NET Standard 2.1

.NET Standard 2.0

.NET 8.0

.NET 7.0

Version Downloads Last updated
2.66.0 23 10/22/2024
2.65.0 20 10/02/2024
2.61.0 21 02/28/2024
2.60.0 20 01/22/2024
2.55.0 19 08/06/2023
2.50.0 19 10/07/2023