Hello NestForge gRPC
What the gRPC-first example includes, how it maps tonic services to NestForge providers, and how to read the project.
Run the example
Section titled “Run the example”Example location:
examples/hello-nestforge-grpcRun it from the repository root:
cargo run -p hello-nestforge-grpcThe service listens on 127.0.0.1:50051.
Example purpose
Section titled “Example purpose”This example demonstrates how NestForge can provide module wiring and dependency
injection while tonic remains the concrete gRPC transport boundary.
Files included
Section titled “Files included”The example currently includes:
src/main.rssrc/app_module.rssrc/app_config.rssrc/grpc/mod.rssrc/grpc/patterns.rssrc/grpc/service.rssrc/grpc/proto/mod.rssrc/grpc/proto/hello.rsproto/greeter.proto
Recommended reading order
Section titled “Recommended reading order”Read the example in this order:
proto/greeter.protosrc/app_module.rssrc/grpc/patterns.rssrc/grpc/service.rssrc/main.rs
What each file does
Section titled “What each file does”src/main.rs
Section titled “src/main.rs”Creates NestForgeGrpcFactory::<AppModule>, binds to 127.0.0.1:50051, and mounts the
generated tonic GreeterServer.
src/app_module.rs
Section titled “src/app_module.rs”Registers application config and a GrpcPatterns provider, then exports both.
src/grpc/patterns.rs
Section titled “src/grpc/patterns.rs”Builds a MicroserviceRegistry with the hello.say message pattern. This is a key
design detail: the example uses the microservice pattern layer as business logic behind
the gRPC transport.
src/grpc/service.rs
Section titled “src/grpc/service.rs”Implements the tonic-generated Greeter trait. It validates the request, resolves the
pattern registry from GrpcContext, dispatches the request through
dispatch_grpc_message(...), and maps the payload back into a gRPC response.
proto/greeter.proto
Section titled “proto/greeter.proto”Defines the public transport contract.
Important current-state note
Section titled “Important current-state note”In this workspace snapshot, the example already includes generated bindings under
src/grpc/proto/ and does not currently include a local build.rs file. That means the
docs should be read against the checked-in example as it exists now, not against an older
generic tonic template.
What users learn from this example
Section titled “What users learn from this example”- how NestForge DI works in a gRPC-first app
- how to keep transport code thin
- how to bridge gRPC and transport-neutral microservice patterns
- how config providers remain available inside the service layer
What to verify
Section titled “What to verify”When running the example, verify:
- the contract is defined in
proto/greeter.proto GrpcPatternsresolves throughGrpcContext- the service dispatches into
hello.say - the tonic server is mounted by
NestForgeGrpcFactory