$ show grpc/grpc-dotnet
This repository is the official gRPC implementation for .NET (grpc-dotnet), providing a comprehensive set of libraries for building gRPC services and clients on ASP.NET Core. It includes server-side integration via `Grpc.AspNetCore.Server` with full support for unary, server-streaming, client-streaming, and duplex streaming calls, as well as client-side libraries (`Grpc.Net.Client`, `Grpc.Net.ClientFactory`) that leverage `HttpClient` and DI. The codebase also covers gRPC-Web (both server middleware and client handler), health checks, server reflection, load balancing, retry/hedging policies, compression, interceptors, and a CLI tool (`dotnet-grpc`) for managing protobuf references. The architecture is modular, with clear separation of concerns: core abstractions in `Grpc.Core.Api`, shared utilities in `Grpc.Net.Common`, and platform-specific implementations. Extensive unit and functional tests, performance benchmarks, and interop test assets ensure correctness and performance across .NET versions and platforms.
The LLM identified 8 files worth highlighting for reuse:
Provides `ReadAllAsync()` extension method that converts an `IAsyncStreamReader<T>` into an `IAsyncEnumerable<T>`, enabling `await foreach` consumption of gRPC streaming responses. This is a clean, isolated utility that can be reused in any project needing to iterate over async streams.
Implements configurable exponential backoff with jitter for retry logic. The policy is parameterized with initial delay, max delay, and multiplier, and uses a random jitter factor. This is a standalone, well-tested component that can be extracted for any retry or rate-limiting scenario.
A `PipeReader` implementation that decodes base64-encoded gRPC-Web frames on the server side. It handles partial frames, remainder bytes, and supports both standard and URL-safe base64. This is a self-contained, testable component for any scenario requiring base64 decoding of piped data.
A `MemoryStream` subclass that overrides `Dispose` to be a no-op, preventing accidental disposal in scenarios where the stream is reused. Useful in testing and serialization contexts where ownership is shared. Simple, isolated, and directly reusable.
A lightweight async synchronization primitive for coordinating test threads. Provides `WaitAsync()` and `Signal()` methods to pause and resume execution deterministically. This is a common pattern for testing concurrent or async code and can be extracted into any test project.
A test fixture that sets up an in-process ASP.NET Core server with gRPC endpoints, supporting multiple protocols (HTTP/2, HTTP/3, gRPC-Web) and custom configurations. It manages server lifecycle, logging, and client creation. This pattern is reusable for any gRPC integration testing scenario.
Base class for strongly-typed service configuration objects (e.g., `RetryPolicy`, `MethodConfig`, `LoadBalancingConfig`). Uses dictionary-based parsing with type converters for durations, status codes, and nested objects. This pattern is reusable for any JSON-like configuration parsing with validation.
A thread-safe lookup that starts as a simple array-based cache and falls back to a full `ConcurrentDictionary` when a threshold is exceeded. Optimized for read-heavy, low-contention scenarios. This is a reusable concurrent data structure pattern.