On 26 Jun 2012, at 13:53, André Salvati wrote:

> I'm trying to use Guice to instantiate my Objectify DAOs. My hierarchy is the 
> following:
> 
> public class EmpresaDao extends ObjectifyDao<Empresa> { ... }
> 
> public class ObjectifyDao<T> extends DAOBase { ... }
> 
> When I use "new EmpresaDao()", getClass().getGenericSuperclass() gives me:
> 
>     [INFO] superclass -> 
> br.com.xxxxx.server.service.ObjectifyDao<br.com.xxxxx.domain.Empresa>
> 
> When I use "injector.getInstance(EmpresaDao.class)", 
> getClass().getGenericSuperclass() gives me:
> 
>     [INFO] superclass -> class br.com.xxxx.server.service.EmpresaDao
> 
> Obviously, I want to let Guice instantiate my objects with DI.
> 
> Can someone explain why this is happen?

What does instance.getClass() show when using the injector?  If the name 
contains "ByGuice" then Guice has created an intermediate proxy, which is why 
the superclass differs.

Guice creates proxies to handle method interception (AOP) or to break circular 
dependencies - you could try turning off the circular dependency proxy feature 
in your module:

   
http://google-guice.googlecode.com/git/javadoc/com/google/inject/Binder.html#disableCircularProxies()

or alternatively if you don't need AOP then you can use the "no_aop" flavour of 
Guice. 

> Is there any way (instantiating with Guice) to get the same superclass as 
> with new().
> 
> Thanks.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "google-guice" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/google-guice/-/nD9OpdD__GEJ.
> 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.

-- 
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.

Reply via email to