I'm trying to figure out a way to determine the class name and package
of *what* is being injected for constructor injection, in time for a
Provider to give a different result based on that information.
Background: I'm helping out some folks who have a bunch of legacy
code which is littered with code that reads properties files from
disk. The goal is to migrate them to something where the
configuration could come from a central admin server or wherever; and
to get business logic out of the business of reading configuration
from anywhere.
I've done this sort of thing with @Named before, so it's no problem to
handle loading primitives from some layered stack of properties
objects which might or might not be the files on disk they're used to
using (and, for the first cut, probably will be).
Caveats are:
- In some cases a property file may still need to be available for
backward compatibility
- This is a small team, and I need to give them something
incrementally useful, not something where all the code must be
rewritten at once - they need to be able to evolve toward a better
approach
I've already taken care of how properties get *written* - you can
annotate classes with
@Defaults(value={"foo=bar"}, namespace=@Namespace("log-service"))
and an annotation processor will generate properties files in the
right spot on the classpath, and I can load and merge all such at
runtime (so we can start deleting things that have reasonable global
defaults and letting those settings live with the code that consumes
them). So figuring out what to inject for a given property name in a
given namespace is solved.
It's easy to solve the case of explicit requests for a namespaced
value - just use my own @Named clone with a namespace parameter:
Foo (@Value(name="foo-port", namespace=@Namespace("log-service"))
{ ... }
But, these guys are new to Guice and I want to give them a good, and
*non-verbose* experience. What seems optimal would be to be able to
add the
@Namespace("log-service")
on a class or package annotation, and my Guice plumbing will figure
out where to look for the values it injects.
So, that's where I'm stuck. Rightly, Guice can't hand me an instance
of an object that hasn't been created yet; and I know that sometimes
it will be a magic FastClassByGuice insta-subclass.
But it seems like there ought to be a way to get the metadata of the
type which will be injected, so that I could walk its hierarchy and
find an @Namespace annotation on its class or its package or its
package's parent packages.
Am I just missing something obvious?
-Tim
--
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.