You can take a look here: https://bitbucket.org/noctarius/guiceidentityinjection/src/014f6cb8fcc0/src/main/java/com/google/inject/identityinjection/IdentityProviderFactory.java
It takes a mixture of PrivisionListener, ThreadLocal and Factory. On 30 Aug., 14:43, "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 > thehttp://code.google.com/p/google-guice/wiki/CustomInjectionsas 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 [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
