Yup, that is the hack I ended up figuring out (well, I did requestInjection(this), but same idea). I just figured there might be a cleaner way to do this :)
On Nov 12, 8:10 pm, Bob Lee <[email protected]> wrote: > Would something like this work? > > public class LogglyModule extends AbstractModule { > @Override protected void configure() { > requestInjection(new Object() { > @Inject void configureLoggly(@Configuration Properties config) { > // Configure Loggly. > ... > } > }); > } > > } > > It won't work if you need Loggly in your modules. If you need that, you'll > just have to share the Properties outside of Guice. > > Bob > > On Sat, Nov 12, 2011 at 8:00 PM, Patrick Lightbody <[email protected]>wrote: > > > > > > > > > I'm faced with a situation that I'm not sure Guice supports, which > > makes me think this is one of those "you're doing it wrong" > > situations. So I'll go ahead and explain what I'd like, but feel free > > to point out that I'm thinking about it incorrectly and show me the > > Guice Way to do the same thing :) > > > Here's my situation: I have a ConfigurationModule, which reads a > > properties file and binds it as various @Named attributes. However, > > for a variety of reasons, it's sometimes preferable for my code to > > work directly with the Properties class, so it also binds it against > > the @Configuration annotation. So far so good. > > > But I also have a LogglyModule, which when used should configure the > > JVM to use Loggly (a SaaS logging service) by using some configuration > > in the properties file. My preference is for LogglyModule to somehow > > have access to the Properties object, but I can't figure out any way > > to get this from Binder. > > > I understand that perhaps I may be misusing the Module concept, since > > normally Modules are supposed to bind x to y and in this case I am > > just using it to run some configuration code, but it just feels so > > damn convenient to mix in a LogglyModule alongside > > ConfigurationModule, FooModule, BarModule, etc. > > > Any recommendations? > > > Patrick > > > -- > > You received this message because you are subscribed to the Google Groups > > "google-guice" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > >http://groups.google.com/group/google-guice?hl=en. -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
