I have Dao<T>
interface which is implemented by BaseDao<T>
class & BaseDao<T>
later extended by many of subclass like UserDao
class.
interface Dao<T>{}
abstract class BaseDao<T> implements Dao<T>{}
class UserDao extends BaseDao<User>{}
Following is the guice binding
bind(new TypeLiteral<Dao<User>>() {
}).annotatedWith(Names.named("UserDao")).toProvider(UserDaoProvider.class);
Provider looks like..
public class UserDaoProvider implements Provider<UserDao> {
@Override
public UserDao get() {
return new UserDao();
}
}
Now i am trying to get it from guice injector
injector.getInstance(Key.get(new TypeLiteral<Dao<User>>() {
}, Names.named("UserDao")));
But i am getting null
Please help to resolve the issue.
We can get instance of UserDao as follows
injector.getInstance(UserDao.class);