Grpc.Net.ClientFactory 2.50.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,378
SanedBuildingBlocks
This package built for OIG-Saned
2,351
SanedBuildingBlocks
This package built for OIG-Saned
908
SanedBuildingBlocks
This package built for OIG-Saned
831
SanedBuildingBlocks
This package built for OIG-Saned
740
SanedBuildingBlocks
This package built for OIG-Saned
643
KitSys.Common.Protos.DTO
KitSys.Common.Protos.DTO
623
SanedBuildingBlocks
This package built for OIG-Saned
449
SanedBuildingBlocks
This package built for OIG-Saned
419
SanedBuildingBlocks
This package built for OIG-Saned
274
SanedBuildingBlocks
This package built for OIG-Saned
266
SanedBuildingBlocks
This package built for OIG-Saned
189
SanedBuildingBlocks
This package built for OIG-Saned
184
SanedBuildingBlocks
This package built for OIG-Saned
182
SanedBuildingBlocks
This package built for OIG-Saned
123
SanedBuildingBlocks
This package built for OIG-Saned
118
SanedBuildingBlocks
This package built for OIG-Saned
115
SanedBuildingBlocks
This package built for OIG-Saned
112
SanedBuildingBlocks
This package built for OIG-Saned
108
SanedBuildingBlocks
This package built for OIG-Saned
101

.NET 5.0

.NET Standard 2.1

.NET Standard 2.0

.NET 7.0

.NET 6.0

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