Custom scopes are one way. Assuming there is a well-defined entry point at
which the information you make a SomeData from becomes available, you could
do something like
- Bind SomeData to a provider that will create it on the fly from whatever
you make one from (such as an HTTP request) - call it RawData
- Your Provider<SomeData> will take a Provider<RawData> as an argument
- In your Provider<SomeData> you call get() on the Provider<RawData> and
make a SomeData and return it
- When you have a RawData, enter your custom scope, giving it the RawData,
so that anything injected while the scope knows about the RawData (usually
you put that in a ThreadLocal) will get a SomeData created by your provider
- Ask the injector to construct the object that takes a SomeData, then
use it
I've used this approach to do things like this:
http://timboudreau.com/builds/job/mastfrog-parent/lastSuccessfulBuild/artifact/acteur-modules/acteur-parent/acteur/target/apidocs/com/mastfrog/acteur/preconditions/InjectParametersAsInterface.html
which takes an HTTP request, and lets you pass an interface type, and it
will inject a dynamic proxy that implements the interface and fetches data
from the URL parameters, for example.
For the custom scope part, I wrote a library that can help:
https://github.com/timboudreau/scopes
-Tim
--
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 [email protected].
To post to this group, send email to [email protected].
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/6f22a049-08fe-4335-8375-e7a0e0f3d641%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.