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?
Is there any way (instantiating with Guice) to get the same superclass as with "new ()"?.
Thanks.
Thanks to Stuart McCulloch, who helped me here
It's possible to disable AOP (using Guice whitout AOP) which gives me what I wanted (br.com.xxxxx.server.service.ObjectifyDao) (not tested)
But I want to have AOP on my toolkit, so I've solved by getting the TypeArguments from the proxy classes generated by Guice:
clazz = (Class<T>) ((ParameterizedType) TypeLiteral.get(getClass()).getSupertype(ObjectifyDao.class).getType()).getActualTypeArguments()[0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With