groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From werickson <werick...@gmail.com>
Subject Re: java parser usage in Groovy
Date Wed, 24 Jun 2015 17:59:52 GMT
> What about Dagger2? 
Dagger 2 does not modify existing classes, it will only generate code.

When you @Inject a member or a constructor in Dagger2, you're instructing it
to generate the vanilla code you would have written to do manual dependency
injection yourself.  Dagger2 is much less magical than Google Guice in this
regard.

I think it will become clear if you take a look how the dependency injection
bootstrapping occurs in Dagger2.

>From the Dagger2 website - https://google.github.io/dagger/:
> @Component(modules = DripCoffeeModule.class)
> interface CoffeeShop {
>   CoffeeMaker maker();
> }
> 
> // ...
> 
> CoffeeShop coffeeShop = DaggerCoffeeShop.builder()
>    .dripCoffeeModule(new DripCoffeeModule())
>    .build();
> CoffeeMaker = coffeeShop.maker();

In this example Dagger2 is generating a Component that matches the interface
provided to expose the CoffeeMaker class.  This component is basically used
to bootstrap the object graph that Dagger2 has built up into your
application.

In the Dagger generated code, it knows about all the injectable types that
can go into the constructor or members of the CoffeeMaker class, because you
annotated those types with @Inject or created a provider for it
DripCoffeeModule, and it will provide them, when newing it.  Actual
modification of the CoffeeMaker class by the annotation processor is not
required to make this work.



--
View this message in context: http://groovy.329449.n5.nabble.com/java-parser-usage-in-Groovy-tp5725492p5725534.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Mime
View raw message