Grpc.Net.ClientFactory 2.55.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,379
SanedBuildingBlocks
This package built for OIG-Saned
2,352
SanedBuildingBlocks
This package built for OIG-Saned
909
SanedBuildingBlocks
This package built for OIG-Saned
832
SanedBuildingBlocks
This package built for OIG-Saned
741
SanedBuildingBlocks
This package built for OIG-Saned
645
KitSys.Common.Protos.DTO
KitSys.Common.Protos.DTO
624
SanedBuildingBlocks
This package built for OIG-Saned
450
SanedBuildingBlocks
This package built for OIG-Saned
420
SanedBuildingBlocks
This package built for OIG-Saned
275
SanedBuildingBlocks
This package built for OIG-Saned
267
SanedBuildingBlocks
This package built for OIG-Saned
190
SanedBuildingBlocks
This package built for OIG-Saned
185
SanedBuildingBlocks
This package built for OIG-Saned
183
SanedBuildingBlocks
This package built for OIG-Saned
124
SanedBuildingBlocks
This package built for OIG-Saned
119
SanedBuildingBlocks
This package built for OIG-Saned
116
SanedBuildingBlocks
This package built for OIG-Saned
113
SanedBuildingBlocks
This package built for OIG-Saned
109
SanedBuildingBlocks
This package built for OIG-Saned
102

.NET 5.0

.NET Standard 2.1

.NET Standard 2.0

.NET 7.0

.NET 6.0

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