Dagger--new fast-startup Guice replacement

2,372 views
Skip to first unread message

glenviewjeff

unread,
Sep 29, 2012, 11:20:28 PM9/29/12
to robo...@googlegroups.com
If others haven't heard, there's a new Guice-compatible DI tool called Dagger released by Square.  It does code generation so there's no slow startup.

It doesn't appear to contain RoboGuice's Context/Activity/View injection.  It would be great, Michael and friends, if you would eventually migrate RoboGuice to use Dagger instead of Guice. 

Jeff

Macarse

unread,
Sep 30, 2012, 9:52:12 AM9/30/12
to robo...@googlegroups.com
why?
> --
> You received this message because you are subscribed to the Google Groups
> "roboguice" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/roboguice/-/NTMOVD63o0AJ.
> To post to this group, send email to robo...@googlegroups.com.
> To unsubscribe from this group, send email to
> roboguice+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/roboguice?hl=en.

John Raymond

unread,
Sep 30, 2012, 9:59:43 AM9/30/12
to robo...@googlegroups.com
My understanding is that Dalvik doesn't support runtime code generation, which would make this impossible.

glenviewjeff

unread,
Sep 30, 2012, 10:08:40 AM9/30/12
to robo...@googlegroups.com
John, I'm  not sure I follow.  Dagger is intended for Android alone.  The code generation is done at build time, not at runtime--hence the fast startup times.

Mike Burton

unread,
Sep 30, 2012, 11:53:35 AM9/30/12
to robo...@googlegroups.com
One of the main things I want to focus on in 3.0 is performance, and some of that work may involve a compile time stage to reduce runtime reflection
--
You received this message because you are subscribed to the Google Groups "roboguice" group.
To view this discussion on the web visit https://groups.google.com/d/msg/roboguice/-/Am3i87tVDrAJ.

Edward Dale

unread,
Sep 30, 2012, 11:58:21 AM9/30/12
to robo...@googlegroups.com
The Android Annotations might make a better companion to Dagger than a redesigned RoboGuice. They already use annotations to provide compile-time injection of views [1] among other things. I haven't used it yet, but I'm planning on spending a day investigating the combination instead of my current RoboGuice setup.

1) https://github.com/excilys/androidannotations/wiki/Injecting-Views


On Sunday, September 30, 2012 at 5:20 AM, glenviewjeff wrote:

> If others haven't heard, there's a new Guice-compatible DI tool called Dagger (https://github.com/square/dagger)released by Square. It does code generation so there's no slow startup.
>
> It doesn't appear to contain RoboGuice's Context/Activity/View injection. It would be great, Michael and friends, if you would eventually migrate RoboGuice to use Dagger instead of Guice.
>
> Jeff
> --
> You received this message because you are subscribed to the Google Groups "roboguice" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/roboguice/-/NTMOVD63o0AJ.
> To post to this group, send email to robo...@googlegroups.com (mailto:robo...@googlegroups.com).
> To unsubscribe from this group, send email to roboguice+...@googlegroups.com (mailto:roboguice+...@googlegroups.com).

glenviewjeff

unread,
Sep 30, 2012, 12:30:57 PM9/30/12
to robo...@googlegroups.com
From what I recall, AndroidAnnotations cannot inject Context or Activity.  I first read about AndroidAnnotations with excitement until I learned this. 

Johnathan Raymond

unread,
Sep 30, 2012, 12:39:19 PM9/30/12
to robo...@googlegroups.com
Reading the "upgrading from guice" section, it sounds like more of a fork candidate than a migration candidate, bringing features of one to the other - because some of its limitations are things I use heavily in RG.  
To view this discussion on the web visit https://groups.google.com/d/msg/roboguice/-/kZ-M4cA8kMIJ.
To post to this group, send email to robo...@googlegroups.com.
To unsubscribe from this group, send email to roboguice+...@googlegroups.com.

glenviewjeff

unread,
Oct 2, 2012, 9:01:22 AM10/2/12
to robo...@googlegroups.com
Really?  What features of Guice do you believe that you are using heavily that are in the list of unsupported features?

Johnathan Raymond

unread,
Oct 2, 2012, 12:46:46 PM10/2/12
to robo...@googlegroups.com
Mostly Injection of POJO's (For integrating with non - guiced code, eventing) - I also tend to keep my View objects private and final, though I admit that this is easy to work around if the implementation changed.  I think what I'm getting at is that importing the idea of precompilation from dagger would be beneficial, without necessarily converting wholesale and thus keeping roboguice relatively intact.  Perhaps a mix of the aggressive precompilation aspects with the more passive reflection?

To view this discussion on the web visit https://groups.google.com/d/msg/roboguice/-/yV1SZL1FpIQJ.

glenviewjeff

unread,
Oct 2, 2012, 1:53:32 PM10/2/12
to robo...@googlegroups.com
I think I may have misinterpreted the "Classes that lack @Inject annotations cannot be constructed by Dagger" limitation as meaning that they couldn't top-level sources of injection, but that would be odd.  I'm sure your interpretation is correct--quite annoying in my case, but fixable. 

To work around this with non-Guice code, you could write provider factories.  Ugly, but it would work. 

Pierre-Yves Ricau

unread,
Oct 29, 2012, 9:57:31 AM10/29/12
to robo...@googlegroups.com
Hi,

I just bumped on this thread.

I'm glad to see that RoboGuice 3.0 will improve performances!

As soon as I heard of Dagger, I of course wondered if there'd be ways to use it with AndroidAnnotations. I spent a bit of time on this idea a few weeks ago, and came up with an example : https://github.com/pyricau/androidannotations-dagger-example . There were a few gotchas, but I think that's mostly due to Dagger young age.

The idea would probably be to extend AndroidAnnotations so that it generates a Dagger module for the AndroidAnnotations generated class.

"From what I recall, AndroidAnnotations cannot inject Context or Activity.  I first read about AndroidAnnotations with excitement until I learned this."

This isn't exactly true (@RootContext), but I agree that it's not as flexible as it is with RoboGuice. This will really change with AndroidAnnotations 3.0.

Regarding Dagger, I'm still waiting for an Android app example to see how they implement activity / context injection, since there is no notion of Scope. Right now, it seems that the way to go is to use an EventBus such as Otto to propagate the activity instance. It works fine but I'd rather have it injected. RoboGuice does that just fine.

Cheers,
Pierre-Yves Ricau - creator of AndroidAnnotations

2012/10/2 glenviewjeff <glenvi...@gmail.com>
To view this discussion on the web visit https://groups.google.com/d/msg/roboguice/-/C_JuyMQgxuYJ.

To post to this group, send email to robo...@googlegroups.com.
To unsubscribe from this group, send email to roboguice+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/roboguice?hl=en.



--
Pierre-Yves Ricau


Reply all
Reply to author
Forward
0 new messages