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,423
SanedBuildingBlocks
This package built for OIG-Saned
2,421
KitSys.Common.Protos.DTO
KitSys.Common.Protos.DTO
1,302
SanedBuildingBlocks
This package built for OIG-Saned
912
SanedBuildingBlocks
This package built for OIG-Saned
833
SanedBuildingBlocks
This package built for OIG-Saned
753
SanedBuildingBlocks
This package built for OIG-Saned
647
SanedBuildingBlocks
This package built for OIG-Saned
456
SanedBuildingBlocks
This package built for OIG-Saned
422
KitSys.Purchase.Protos.Client
KitSys.Purchase.Protos.Client
414
KitSys.KeycloakClient.Protos.Client
KitSys.KeycloakClient.Protos.Client
412
KitSys.MailService.Protos.Client
KitSys.MailService.Protos.Client
408
KitSys.PlatformsAdminstrations.Protos.Client
KitSys.PlatformsAdminstrations.Protos.Client
407
KitSys.NawrasRewardAndRecognition.Protos.Client
KitSys.NawrasRewardAndRecognition.Protos.Client
406
KitSys.NotificationManager.Protos.Client
KitSys.NotificationManager.Protos.Client
404
KitSys.KitsysFileware.Protos.Client
KitSys.KitsysFileware.Protos.Client
403
KitSys.Nawras.Protos.Client
KitSys.Nawras.Protos.Client
402
KitSys.KitsysFinance.Protos.Client
KitSys.KitsysFinance.Protos.Client
402
KitSys.SuccessionManagement.Protos.Client
KitSys.SuccessionManagement.Protos.Client
402
KitSys.NawrasKnowledgeManagement.Protos.Client
KitSys.NawrasKnowledgeManagement.Protos.Client
401

.NET 6.0

.NET Standard 2.1

.NET Standard 2.0

.NET 8.0

.NET 7.0

Version Downloads Last updated
2.66.0 17 10/22/2024
2.65.0 15 10/02/2024
2.61.0 16 02/28/2024
2.60.0 16 01/22/2024
2.55.0 15 08/06/2023
2.50.0 15 10/07/2023