Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sisu-users] strange behaviour of TypeListener

The only thing I can think of without seeing an example project is that AOPCandidate is a concrete class which is not bound in any of the injectors.

In such cases (where all explicit bindings have been exhausted) the container will fall back to implicit bindings. And if AOPCandidate is a concrete class then its implicit binding will potentially exist in any of the injectors, in which case it could be creating the instance in an injector that didn’t have the interceptor installed.

If this is the case then the solution would be to add @Named to AOPCandidate so that it’s indexed and bound by Sisu, or make sure it’s bound in a module belonging to the appropriate injector. You could also enable “binder. requireExplicitBindings” in all the injectors to make sure that implicit bindings are never used.

If you have an example or partial project that recreates this then I’m happy to take a closer look.

-- 
Cheers, Stuart

On Friday, 3 February 2017 at 16:35, Giamma wrote:

Hello,

I am having a strange behaviour related to TypeListeners when using Sisu in an OSGi application.

I created a Guice Module and listed it in the META-INF/services/com.google.inject.Module inside a bundle. The module is properly instantiated by Sisu and the listener registered.

The TypeListener is exepected to add an AOP interceptor to selected classes of the same bundle in which the Guice Module is declared and registered.

Now, if I am instantiating one of the types that should be subject to AOP as follows what I obtain is a properly woven class.

((InjectorBindings)MutableBeanLocator.publishers().get(3)).getInjector().getInstance(org.example.AOPCandidate.class)

If I am instead instantiating the class as follows:

MutableBeanLocator.locate(com.google.inject.Key.get(org.example.AOPCandidate.class)).iterator().next().getValue()

the class is not woven anymore.

The first method consists in unboxing from the bean locator the injector that was created for the bundle and using it directly, while the second approach consists in using the BeanLocator directly, which is what I should do.

What am I doing wrong?  Sisu 0.3.3 and Guice 3.0.

Thanks in advance.
--
Gian Maria Romanato
<gm.romanato (at) gmail (dot) com>
_______________________________________________
sisu-users mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit


Back to the top