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
SanedBuildingBlocks
This package built for OIG-Saned
3,440
KitSys.Common.Protos.DTO
KitSys.Common.Protos.DTO
3,297
SanedBuildingBlocks
This package built for OIG-Saned
2,437
KitSys.KitsysFileware.Protos.Client
KitSys.KitsysFileware.Protos.Client
1,175
KitSys.DataImporter.Protos.Client
KitSys.DataImporter.Protos.Client
1,169
KitSys.Delivery.Protos.Client
KitSys.Delivery.Protos.Client
1,168
KitSys.ClinicSystem.Protos.Client
KitSys.ClinicSystem.Protos.Client
1,148
KitSys.KitsysFinance.Protos.Client
KitSys.KitsysFinance.Protos.Client
1,142
KitSys.SuppliersCustomersPortal.Protos.Client
KitSys.SuppliersCustomersPortal.Protos.Client
1,126
KitSys.MailService.Protos.Client
KitSys.MailService.Protos.Client
1,125
KitSys.NotificationManager.Protos.Client
KitSys.NotificationManager.Protos.Client
1,115
KitSys.SuccessionManagement.Protos.Client
KitSys.SuccessionManagement.Protos.Client
1,112
KitSys.NawrasKnowledgeManagement.Protos.Client
KitSys.NawrasKnowledgeManagement.Protos.Client
1,111
KitSys.NOrganizationPerformanceModelService.Protos.Client
KitSys.NOrganizationPerformanceModelService.Protos.Client
1,109
KitSys.NawrasRewardAndRecognition.Protos.Client
KitSys.NawrasRewardAndRecognition.Protos.Client
1,107
KitSys.SanedTemps.Protos.Client
KitSys.SanedTemps.Protos.Client
1,106
KitSys.NawrasCompliance.Protos.Client
KitSys.NawrasCompliance.Protos.Client
1,104
KitSys.NotificationService.Protos.Client
KitSys.NotificationService.Protos.Client
1,098
KitSys.LogisticSystem.Protos.Client
KitSys.LogisticSystem.Protos.Client
1,095
KitSys.Nawras.Protos.Client
KitSys.Nawras.Protos.Client
1,094

.NET 6.0

.NET Standard 2.1

.NET Standard 2.0

.NET 8.0

.NET 7.0

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