On 27 Oct 2013, at 15:59, cowwoc wrote:
>
> What happens if I take
> https://code.google.com/p/google-guice/wiki/CustomInjections and change:
>
> field.isAnnotationPresent(InjectLogger.class)
>
> to
>
> field.isAnnotationPresent(Inject.class)
>
> Wouldn't that work as I expect?
I don't believe so, because Guice will report the missing binding as an error
before it gets round to starting custom injection.
The only way I've found to provide a kind of "auto-binding" without modifying
Guice internals is to use the SPI to scan for missing dependencies and then add
bindings for them.
For example:
Guice.createInjector( new WireModule( appModuleA, appModuleB,
serviceModuleC ) );
where WireModule uses Elements.elements(...) to process, analyze, and reapply
the various elements - keeping track of what dependencies are used and what
keys are bound.
The downside of this approach is that you need to remember wrap the WireModule
around your application modules, as well as the up-front cost of analyzing the
elements. It also doesn't work so well with just-in-time bindings (such as
asking the injector for an instance of FooImpl.class, where FooImpl is not
referenced at all in the bindings provided to the injector and therefore was
not available for analysis).
The benefit of doing the analysis upfront is that the final binding elements
are static and can be analyzed by tooling just like those from any other module.
> Gili
>
> On 27/10/2013 11:53 AM, Sam Berlin wrote:
>> Issue 49 provides a good history of this request -- currently closed as
>> "Won't Fix".
>>
>> sam
>>
>>
>> On Sun, Oct 27, 2013 at 11:45 AM, cowwoc <[email protected]> wrote:
>> Hi Sam,
>>
>> Out of curiosity, is it possible to make this work using @Inject instead
>> of @InjectLogger? As in:
>>
>> @Inject Logger logger;
>>
>> The goal is to intercept @Inject for an unknown type, and ask HK2 to try
>> injection. Using custom annotations kind of defeat the purpose (we already
>> have @HK2Inject which we're trying to get away from).
>>
>> Gili
>>
>>
>> On 27/10/2013 11:24 AM, Sam Berlin wrote:
>>> There's no built-in way to do this. Depending on the scope, it's maybe
>>> possible to use TypeListeners and custom injections to do this.
>>>
>>> sam
>>>
>>>
>>> On Sun, Oct 27, 2013 at 11:19 AM, Gili <[email protected]> wrote:
>>> I am trying to integrate two DI systems: Guice and HK2. I'd like to
>>> implement the following behavior:
>>>
>>> 1. When Injector.getInstance() is invoked, iterate through all bindings (as
>>> it normally does).
>>> 2. If no match is found, ask HK2 to inject the type.
>>> 3. If no match is found, throw an error.
>>>
>>> I'm not sure how to implement step #2. Because we lack this behavior, we're
>>> stuck with an ugly @HK2Inject as seen here:
>>> https://hk2.java.net/guice-bridge/index.html
>>>
>>> Any ideas?
>>>
>>> Gili
>>> --
>>> 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.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "google-guice" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/google-guice/YXJuAdw5G24/unsubscribe.
>>> To unsubscribe from this group and all its topics, 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.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>> --
>> 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "google-guice" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/google-guice/YXJuAdw5G24/unsubscribe.
>> To unsubscribe from this group and all its topics, 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
--
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.
For more options, visit https://groups.google.com/groups/opt_out.