Dependencies

70 views
Skip to first unread message

Michiel ten Hagen

unread,
Sep 10, 2015, 7:00:44 AM9/10/15
to google-guice
All

I have two classes, Cache and CacheMonitor.  If someone binds the Cache I want the CacheMonitor to be initiated.

Currently I have the Cache class depend on the CacheMonitor but this creates a unnecassary dependency, the Cache should be able to be used without the CacheMonitor.

Is there a way to specify that CacheMonitor should be loaded only if the Cache is binded?

Regards,

Michiel


Nate Bauernfeind

unread,
Sep 10, 2015, 9:48:11 AM9/10/15
to google-guice
Maybe you want to make CacheMonitor an optional dependency?


--
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/9a306fd5-1170-4496-af05-372fb09b05a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Fred Faber

unread,
Sep 10, 2015, 12:56:35 PM9/10/15
to google...@googlegroups.com
An idiomatic solution is to create a CacheModule which you would ask clients of Cache to install.

Within the module you would:
  1. create the binding for Cache
  2. add any additional logic for your CacheMonitor

Not knowing anything about either of these classes it's difficult to say what (2) would look like. If there is significant work to "initiate" the monitor then consider binding this as a Guava Service and using a ServiceManager to execute the logic within your server's main().

Fred

Reply all
Reply to author
Forward
0 new messages