MentaContainer

Compare Revisions

Ignore whitespace Rev 104 → Rev 105

/trunk/src/test/java/org/mentacontainer/impl/GenericFactoryTest.java
27,7 → 27,7
Container c = new MentaContainer();
// giveMeSomething => method that will be called to return object
Factory generic = new GenericFactory(factory, "giveMeSomething", String.class);
Factory generic = new GenericFactory(factory, "giveMeSomething");
c.ioc("myFactory", generic);
/trunk/src/main/java/org/mentacontainer/impl/GenericFactory.java
13,18 → 13,18
private final Class<? extends Object> type;
public GenericFactory(Object factory, String methodName, Class<? extends Object> type) {
public GenericFactory(Object factory, String methodName) {
this.factory = factory;
this.type = type;
try {
this.method = FindMethod.getMethod(factory.getClass(), methodName, new Class[] { });
this.method.setAccessible(true);
this.type = method.getReturnType();
} catch(Exception e) {
throw new RuntimeException(e);
/trunk/src/main/java/org/mentacontainer/example/BasicOperations.java
19,6 → 19,7
case7();
case8();
case9();
case10();
}
 
public static class Connection {
241,5 → 242,33
 
service.doSomething(); // ==> "saoj"
}
public static class SomeService2 {
 
private final UserDAO userDAO;
 
public SomeService2(UserDAO userDAO) {
this.userDAO = userDAO;
}
public void doSomething() {
System.out.println(userDAO.getUsername(11));
}
}
 
private static void case10() {
 
Container c = new MentaContainer();
 
c.ioc("userDAO", JdbcUserDAO.class);
 
c.ioc("connection", Connection.class);
 
c.autowire("connection");
SomeService2 service = c.construct(SomeService2.class);
 
service.doSomething(); // ==> "saoj"
}
 
}