Skip to main content

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

I played with ProvisionListener earlier toda and it did not do what I
need.

From what I understood, ProvisionListener is invoked on component
provisioning, i.e. instance creation, not component injection. Going
back to my example, if ComponentA is @Singleton, ProvisionListener
will be called only once for the ComponentA instance even if it is
injected in multiple ComponentB instances.

I also looked at InjectionListener, which is invoked on each ComponentA
injection, but I could not find a way to locate target ComponentA instance.

Have I misunderstood the API?

--
Regards,
Igor

On 2014-03-01, 15:37, Stuart McCulloch wrote:
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

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



Back to the top