I've just tried out Guice for the first time today and it has impressed me... I've only touched the surface.
Do all bindings have to be defined in the source code? I'd like to make that sort of thing runtime definable. Perhaps through an implementation of Module that searches the classpath for an appropriately named properties file (possibly "guice.properties") and sets up the bindings based on what it finds in there.
It doesn't seem to hard to set it up... but before I go reinventing the wheel, does Guice have this functionality already?
> I've just tried out Guice for the first time today and it has > impressed me... I've only touched the surface.
> Do all bindings have to be defined in the source code? I'd like to > make that sort of thing runtime definable. Perhaps through an > implementation of Module that searches the classpath for an > appropriately named properties file (possibly "guice.properties") and > sets up the bindings based on what it finds in there.
> It doesn't seem to hard to set it up... but before I go reinventing > the wheel, does Guice have this functionality already?
> Check out the Names class. It can convert a Properties into a Module > automatically.
> Bob
> On Nov 9, 2007 7:04 AM, Sam.halli...@gmail.com <Sam.Halli...@gmail.com> wrote:
> > Hi all,
> > I've just tried out Guice for the first time today and it has > > impressed me... I've only touched the surface.
> > Do all bindings have to be defined in the source code? I'd like to > > make that sort of thing runtime definable. Perhaps through an > > implementation of Module that searches the classpath for an > > appropriately named properties file (possibly "guice.properties") and > > sets up the bindings based on what it finds in there.
> > It doesn't seem to hard to set it up... but before I go reinventing > > the wheel, does Guice have this functionality already?
> On Nov 9, 12:26 pm, "Bob Lee" <crazy...@crazybob.org> wrote:
> > Check out the Names class. It can convert a Properties into a Module > > automatically.
> > Bob
> > On Nov 9, 2007 7:04 AM, Sam.halli...@gmail.com <Sam.Halli...@gmail.com> wrote:
> > > Hi all,
> > > I've just tried out Guice for the first time today and it has > > > impressed me... I've only touched the surface.
> > > Do all bindings have to be defined in the source code? I'd like to > > > make that sort of thing runtime definable. Perhaps through an > > > implementation of Module that searches the classpath for an > > > appropriately named properties file (possibly "guice.properties") and > > > sets up the bindings based on what it finds in there.
> > > It doesn't seem to hard to set it up... but before I go reinventing > > > the wheel, does Guice have this functionality already?
Thanks Rob and Adam... that was pretty much what I was after. Any thoughts on expanding on this functionality? Personally I was a little surprised that Guice didn't look for a properties (or horrible XML) file by default... or that there wasn't a simple convenience class for simply instantiating an Injector with a package-name based property reader like
I will probably do something like this... please let me know if you are aware of any problems with this technique. (Of course, defaults can be specified through annotations as usual).
Regarding why Guice doesn't load the Properties for you, I figured there are tons of different ways to do this and tons of libraries which already tackle it, so there wasn't much of a need to duplicate the effort in Guice. I suppose we could support a really simple case out of the box though, i.e. looking for "/guice.properties" in the classpath and blowing up if we find more than one (how often has that problem bitten you?).
Bob
On Nov 9, 2007 11:42 AM, Sam.halli...@gmail.com <Sam.Halli...@gmail.com> wrote:
> Thanks Rob and Adam... that was pretty much what I was after. Any > thoughts on expanding on this functionality? Personally I was a little > surprised that Guice didn't look for a properties (or horrible XML) > file by default... or that there wasn't a simple convenience class for > simply instantiating an Injector with a package-name based property > reader like
> I will probably do something like this... please let me know if you > are aware of any problems with this technique. (Of course, defaults > can be specified through annotations as usual).
I think a big benefit of Guice is the lack of "magic". I can look at my java code and understand what's going on. If a properties file was automatically loaded up I think it would increase the magic factor - which judging by the current design is something that's avoided.
I do see how it would be useful, though.
On Nov 9, 2:50 pm, "Bob Lee" <crazy...@crazybob.org> wrote:
> Regarding why Guice doesn't load the Properties for you, I figured > there are tons of different ways to do this and tons of libraries > which already tackle it, so there wasn't much of a need to duplicate > the effort in Guice. I suppose we could support a really simple case > out of the box though, i.e. looking for "/guice.properties" in the > classpath and blowing up if we find more than one (how often has that > problem bitten you?).
> Bob
> On Nov 9, 2007 11:42 AM, Sam.halli...@gmail.com <Sam.Halli...@gmail.com> wrote:
> > Thanks Rob and Adam... that was pretty much what I was after. Any > > thoughts on expanding on this functionality? Personally I was a little > > surprised that Guice didn't look for a properties (or horrible XML) > > file by default... or that there wasn't a simple convenience class for > > simply instantiating an Injector with a package-name based property > > reader like
> > I will probably do something like this... please let me know if you > > are aware of any problems with this technique. (Of course, defaults > > can be specified through annotations as usual).- Hide quoted text -
On Nov 9, 2007 12:02 PM, Adam Schaible <adam.schai...@gmail.com> wrote:
> I don't see how it can > hurt, but one thing I like about Guice is there are no secrets in your > code. I can figure everything out by reading the code - and if I auto- > loaded some sort of properties file, I think it would add to the > magic.
I couldn't agree more. There's nothing worse than having to debug framework code. I can't count how many hours I wasted trying to get XML files in just the right places with just the right names, and then figuring out if they weren't having the desired affect because of my mistake or an inadequacy in the framework. Usually, it was the latter.
On 10/11/2007, Bob Lee <crazy...@crazybob.org> wrote:
> On Nov 9, 2007 12:02 PM, Adam Schaible <adam.schai...@gmail.com> wrote: > > I don't see how it can > > hurt, but one thing I like about Guice is there are no secrets in your > > code. I can figure everything out by reading the code - and if I auto- > > loaded some sort of properties file, I think it would add to the > > magic.
> I couldn't agree more. There's nothing worse than having to debug > framework code. I can't count how many hours I wasted trying to get > XML files in just the right places with just the right names, and then > figuring out if they weren't having the desired affect because of my > mistake or an inadequacy in the framework. Usually, it was the latter.
totally agree - I wouldn't want this enabled by default as it means you're at the mercy of whoever assembled the classpath and the order of its entries