Overload ServerBuilder.addService to take a Supplier of the service definition
- Lingua principale
- Java
- Stelle
- 12.1k
- Fork
- 4k
- Merge medio
- 2g 17h
- PR unite (30g)
- 37
Descrizione
In general, servers want to instantiate a new method handler for each call to avoid polluted state. We'd like this to be handled by the framework, rather than asking application developers to remember it. The current API essentially pushes the responsibility to the application:
- The `Server` is a singleton since it has a long-lived lifecycle
- `ServerBuilder.addService(ServerServiceDefinition service)` requires that the `service` be instantiated at startup
- `FooServiceGrpc.bindService(FooService serviceImpl)` also requires that the `serviceImpl` be instantiated. Thus, the `FooService` has to be a singleton with respect to the server lifecycle. That is, your implementation of the generated service stub has to be a singleton. So the app developer has to worry about the scope of the dependency chain from there down.
I propose overloading the generated code to take a `Supplier` of some sort: `FooServiceGrpc.bindService(Supplier serviceImplSupplier)`. This would let me pass a Guice `Provider::get` to the `bindService` method and get whatever Guice scoping I want on method calls. This lets me handle proper scoping in my own framework code rather than in every implementation of a stub.
Almost as good would be pushing the thunk-ness back a layer to `ServerBuilder.addService(Supplier serviceSupplier)`, but I suspect that is harder to implement.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia leggendo le API esistenti ServerBuilder.addService(ServerServiceDefinition) e FooServiceGrpc.bindService(FooService) per capire dove vengono create le istanze del servizio. Definisci quale API dovrebbe accettare un supplier e come la creazione del servizio per chiamata interagisce con il ciclo di vita del server e con il codice generato. Il lavoro è completato quando l'overload selezionato supporta il comportamento di scope richiesto senza richiedere implementazioni singleton del servizio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- backend-api-design
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100