I am using Picocontainer in a study project. I am having doubts about how to use it.
The following is the class I have :
public class DependencySupplier {
public static MutablePicoContainer pico;
static {
pico = new DefaultPicoContainer();
pico.registerComponentImplementation(CollectionDao.class, CollectionDaoImpl.class);
pico.registerComponentImplementation(ReadingDao.class, ReadingDaoImpl.class);
pico.registerComponentImplementation(CollectionDetails.class, CollectionDetailsImpl.class);
pico.registerComponentImplementation(Reading.class, ReadingImpl.class);
}
public static CollectionDao getCollectionDao() {
return (CollectionDao) pico.getComponentInstance(CollectionDao.class);
}
public static ReadingDao getReadingDao() {
return (ReadingDao) pico.getComponentInstance(ReadingDao.class);
}
}
My doubts are:
- Is this the right way to use pico ?
The AddressImpl class is as follows:
public class AddressImpl implements Address { private String address1; private String address2; private String address3; private String address4; public AddressImpl(String address1, String address2, String address3, String address4) { super(); this.address1 = address1; this.address2 = address2; } public String getAddress1() { return address1; } public void setAddress1(String address1) { this.address1 = address1; } public String getAddress2() { return address2; } public void setAddress2(String address2) { this.address2 = address2; } public String getAddress3() { return address3; } }
How can I instantiate the Address object with the above implementation as 'address1' and 'address2' has to be supplied by user and will be available on run time ?