Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sisu-users] watching injected components

On 1 Mar 2014, at 19:26, Igor Fedorenko <igor@xxxxxxxxxxxxxx> wrote:

> Say I have a couple of components, ComponentA and ComponentB
> 
>   @Named
>   class ComponentA {}
> 
>   @Named
>   class ComponentB {
>      @Inject
>      ComponentA a;
>   }
> 
> Does sisu (or guice for that matter) provide a way to observe injection
> of ComponentA instances into ComponentB instances?
> 
> To give some context, I develop a maven extension that needs to track
> what objects are injected in Mojo instances and it needs to have
> per-Mojo breakdown of all injected components.

The API that comes closest is probably the Guice ProvisionListener API:

	https://code.google.com/p/google-guice/source/browse/core/src/com/google/inject/spi/ProvisionListener.java

This lets you intercept the provisioning of any objects initiated by Guice and also provides the dependency chain that led to the object being provisioned - you’ll need to drill down the chain into the Dependency then the InjectionPoint if you want to know the exact declaring type and member (constructor, method, field etc.)

You can bind a listener for all bindings as follows:

	bindListener(Matchers.any(), myProvisionListener);  // you can narrow down the matching if you know what bindings you’re interested in

	https://code.google.com/p/google-guice/source/browse/core/src/com/google/inject/Binder.java#379

See also https://code.google.com/p/google-guice/issues/detail?id=78#c16

> --
> Regards,
> Igor
> _______________________________________________
> sisu-users mailing list
> sisu-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/sisu-users



Back to the top