Closed rschulman closed 7 years ago
I'm not sure you need to pass context to each method.
When you implement grpc service, you implement generated service trait, e. g.
// generated trait by protoc-gen-rust-grpc
trait HelloService { ... }
struct MyHelloServiceImpl {
// HERE you can store global state
}
impl HelloService for MyHelloServiceImpl { ... }
Ok, that's interesting. Do you then create an instance of MyHelloServiceImpl
and pass that to HelloServiceAsyncServer::new()
?
Yes, exactly.
It would be nice to be able to pass some arbitrary type to the rpc handlers from the server, in order to gain access to some global state across the entire application. I've been looking through the code, but I'm not seeing any way to do this yet.
If it isn't a feature yet, it seems like it would require a modification to the MethodHandlers in server.rs?