how to replace a RoboGuice default binding?

133 views
Skip to first unread message

kevin wu

unread,
Jul 13, 2014, 1:35:20 AM7/13/14
to robo...@googlegroups.com
I want to inject a ContentResolver into a POJO class.  In my AbstractModule sublcass, I've created a provider that simply gets the content resolver from my application's context.  I've also bound ContentResolver.class to the provider.

When I start my application, however, RoboGuice says that "A binding to android.content.ContentResolver was already configured at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:140)".

How do I resolve this?

Actually it looks like there's a placeholder for this how-to on RoboGuice's github, called "Remove or replace RoboGuice's default bindings"...


Alternatively, is there a way to use a RoboGuice-provided injection in a POJO class?  I suppose I'd like to know both :)

Michael Burton

unread,
Jul 13, 2014, 8:21:25 PM7/13/14
to robo...@googlegroups.com
Take a look at Modules.override.  This should get you started: http://stackoverflow.com/a/531110

--
You received this message because you are subscribed to the Google Groups "roboguice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roboguice+...@googlegroups.com.
To post to this group, send email to robo...@googlegroups.com.
Visit this group at http://groups.google.com/group/roboguice.
For more options, visit https://groups.google.com/d/optout.

kevin wu

unread,
Jul 13, 2014, 10:53:33 PM7/13/14
to robo...@googlegroups.com
Cool thanks.

I wasn't entirely sure how to use it.  I thought I had to override the DefaultRoboModule.  I ended up creating a separate module just for my ContentResolver override; then in my Application subclass constructor, I put "Modules.override( new MyGuiceBindings() ).with( new ContentResolverBindingOverride() );".  Hopefully I am not committing any weird faux pas but it seems to work.  Thank you!

Mike Burton

unread,
Jul 13, 2014, 11:10:30 PM7/13/14
to robo...@googlegroups.com, robo...@googlegroups.com
That's about right.  Just make sure you also include an instance of DefaultRoboModule in your modules list, otherwise you won't get any roboguice bindings at all.

Mike Burton
Android Engineering Manager
http://about.me/michaelburton
Reply all
Reply to author
Forward
0 new messages