標題描述了我的問題。如何使用Guice`Module`注入構造函數接受Class的地方?
E.g.
public class EntryDAOModule extends AbstractModule {
@Override
protected void configure() {
bind(EntryDAO.class).to(EntryDTOMongoImpl.class); // what should this be?
}
}
如圖所示,應該是什麼參數.to
,給出以下:
public class GenericDAOMongoImpl<T, K extends Serializable> extends BasicDAO<T, K> {
public GenericDAOMongoImpl(Class<T> entityClass) throws UnknownHostException {
super(entityClass, ConnectionManager.getDataStore());
}
}
public class EntryDAOMongoImpl extends GenericDAOMongoImpl<EntryDTOMongoImpl, ObjectId> implements EntryDAO<EntryDTOMongoImpl> {
private static final Logger logger = Logger.getLogger(EntryDAOMongoImpl.class);
@Inject
public EntryDAOMongoImpl(Class<EntryDTOMongoImpl> entityClass) throws UnknownHostException {
super(entityClass);
}
...
}
我如何實例化EntryDAOMongoImpl
類,像這樣:
Injector injector = Guice.createInjector(new EntryDAOModule());
this.entryDAO = injector.getInstance(EntryDAO.class); // what should this be?
你想從EntryDAOMongImpl的構造提供EntryDTOMongoImpl.class的超級GenericDAOMongoImpl的()構造函數? – 2012-02-10 05:12:23
@johncarl - 對不起 - 添加了'GenericDAOMongoImpl'類來澄清。 – wulfgarpro 2012-02-10 05:13:55
啊,我明白了......在回答路上 – 2012-02-10 05:15:45