Best way to replace dependencies ?

49 views
Skip to first unread message

Kevin Burton

unread,
Jan 22, 2015, 3:55:18 PM1/22/15
to google...@googlegroups.com
Is there a good pattern to *replace* dependencies with new bindings?

During our init, I have the need to replace a standard output logger, with a log4j logger... 

It only needs to happen once.

I was thinking of having some sort of ReplaceableProvider that has a set() method and uses an AtomicReference... 

Nate Bauernfeind

unread,
Jan 22, 2015, 4:28:01 PM1/22/15
to google...@googlegroups.com
Sounds like this depends on exactly what behavior you want.

You can overwrite bindings in a module with an Override's module. See: http://stackoverflow.com/questions/483087/overriding-binding-in-guice

You could use a PrivateModules to divide your object graph to control which chunks get which logger. See: http://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/PrivateModule.html

You could use an OptionalBinder setting the default to your standard logger. http://google.github.io/guice/api-docs/latest/javadoc/com/google/inject/multibindings/OptionalBinder.html

Of course, I might completely miss your question.



--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/c8bdabad-9e5a-44f4-a0e4-a7ca3f65a9e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages