There's a new thing called ProvisionListener
<http://code.google.com/p/google-guice/source/browse/trunk/core/src/com/google/inject/spi/ProvisionListener.java>in
Guice SVN, but not in a released version.  ProvisionListener can give you
access to the dependency hierarchy of why something is being provisioned, as
well as the Key that is being provisioned, both before & after the
provisioning happens.  You can't (by design) change the injected
dependencies or the return value of the provision, though.  You can manually
do things to the provisioned object, though.

Guice explicitly does not allow support for context-dependent injections,
because it would make maintenance a nightmare and debugging even harder than
it already is.

sam

On Tue, Aug 30, 2011 at 8:43 AM, Oleg Estekhin <[email protected]>wrote:

> Hi
>
> Is there some way to inject some constructor parameters in a
> context-dependent way?
>
> For example, there is way to inject instance fields depending on the
> context (both class and instance) using TypeListener's. Taking the
> http://code.google.com/p/**google-guice/wiki/**CustomInjections<http://code.google.com/p/google-guice/wiki/CustomInjections>as
>  example - it there a way to custom-inject the Logger into the
> constructor? Something like the PaymentService class from the example will
> have a constructor "PaymentService( @SomeCustomAnnotationPerhaps Logger
> logger )", and some type listener or whatever will be asked to provide the
> Logger instance, but it will know the class it is providing it for.
>
> The use-case would be almost the same as for custom field/method
> injections, but in the form of custom constructor injection with the ability
> to use the injected value in the constructor.
>
> It can be partially done with @Named constructor parameters and
> corresponding @Named bindings, or with custom binding annotations, but they
> still require an explicit pairing between usage declaration and binding
> declaration and do not allow to create/configure an object to be injected
> into the constructor of injectee class on the fly depending on the injectee'
> class.
>
>
> Oleg
> --
> 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 google-guice+unsubscribe@**
> googlegroups.com <google-guice%[email protected]>.
> For more options, visit this group at http://groups.google.com/**
> group/google-guice?hl=en<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.

Reply via email to