@@ -171,23 +171,24 @@ fun main(args: Array<String>) {
171171
1721721) Add Guice dependency to your project:
173173
174- [dependency, groupId="com.google.inject", artifactId="guice", version="4.2.2 "]
174+ [dependency, artifactId="jooby- guice"]
175175.
176176
177- 2) Bootstrap Guice from application :
177+ 2) Install Guice:
178178
179- .Java
179+ .Installing Guice
180180[source, java, role = "primary"]
181181----
182+
183+ import io.jooby.di.Guiceby;
184+
182185public class App extends Jooby {
183186
184187 {
185- Injector injector = Guice.createInjector(...); <1>
186-
187- registry(injector); <2>
188+ install(new Guiceby()); <1>
188189
189190 get("/", ctx -> {
190- MyService service = require(MyService.class); <3 >
191+ MyService service = require(MyService.class); <2 >
191192 return service.doSomething();
192193 });
193194 }
@@ -197,66 +198,62 @@ public class App extends Jooby {
197198.Kotlin
198199[source, kotlin, role = "secondary"]
199200----
201+ import io.jooby.di.Guiceby
200202import io.jooby.run
201203
202204fun main(args: Array<String>) {
203205 run(args) {
204- val injector = Guice.createInjector(...) <1>
206+ install(Guiceby()) <1>
205207
206- registry(injector) <2>
207-
208208 get ("/") { ctx ->
209- val service = require(MyService::class) <3 >
209+ val service = require(MyService::class) <2 >
210210 service.doSomething()
211211 }
212212 }
213213}
214214----
215215
216- <1> Bootstrap Guice and creates an Injector
217- <2> Integrates javadoc:Jooby[require, java.lang.Class] with Guice
218- <3> Access to an instance provided by Guice
216+ <1> Install Guice extension
217+ <2> The javadoc:Jooby[require, java.lang.Class] call is now resolved by Guice
219218
220219[id=guice-mvc-routes]
221220==== MVC routes
222221
223- Integration of MVC routes with Guice is as simple as:
222+ Guice will also provisioning MVC routes
224223
225-
226224.MVC and Guice
227225[source, java, role = "primary"]
228226----
227+
228+ import io.jooby.di.Guiceby;
229+
229230public class App extends Jooby {
230231
231232 {
232- Injector injector = Guice.createInjector(...); <1>
233+ install(new Guiceby()) <1>
233234
234- registry(injector); <2>
235-
236- mvc(MyController.class); <3>
235+ mvc(MyController.class); <2>
237236 }
238237}
239238----
240239
241240.Kotlin
242241[source, kotlin, role = "secondary"]
243242----
243+ import io.jooby.di.Guiceby
244244import io.jooby.run
245245
246246fun main(args: Array<String>) {
247247 run(args) {
248- val injector = Guice.createInjector(...) <1>
248+ install(Guiceby()) <1>
249249
250- registry(injector) <2>
251-
252- mvc(MyController::class) <3>
250+ mvc(MyController::class) <2>
253251 }
254252}
255253----
256254
257- <1> Bootstrap Guice and creates an Injector
258- <2> Integrates javadoc:Jooby[require, java.lang.Class] with Guice
259- <3> Let Guice creates and provision `MyController`
255+ <1> Install Guice extension
256+ <2> Register a MVC route
260257
261258The lifecycle of `MyController` is now managed by Guice. Also:
262259
0 commit comments