MentaContainer

Compare Revisions

Ignore whitespace Rev 40 → Rev 41

/trunk/src/main/java/org/mentacontainer/example/BasicOperations.java
21,13 → 21,13
c.ioc("myString1", String.class);
String myString1 = (String) c.get("myString1");
String myString1 = c.get("myString1");
System.out.println(myString1); // ==> "" ==> default constructor new String() was used
c.ioc("myString2", String.class).addInitValue("saoj");
String myString2 = (String) c.get("myString2");
String myString2 = c.get("myString2");
System.out.println(myString2); // ==> "saoj" ==> constructor new String("saoj") was used
35,7 → 35,7
.addProperty("minutes", 10) // setMinutes(10)
.addProperty("seconds", 45); // setSeconds(45)
Date myDate1 = (Date) c.get("myDate1");
Date myDate1 = c.get("myDate1");
System.out.println(myDate1); // ==> a date with time 15:10:45
}
46,9 → 46,9
c.ioc("myString", String.class, true /* singleton */).addInitValue("saoj");
String s1 = (String) c.get("myString");
String s1 = c.get("myString");
String s2 = (String) c.get("myString");
String s2 = c.get("myString");
System.out.println(s1 == s2); // ==> true ==> same instance
95,7 → 95,7
// "connection" = the source from where the dependency will come from
c.autowire("conn", Connection.class, "connection");
UserDAO userDAO = (UserDAO) c.get("userDAO");
UserDAO userDAO = c.get("userDAO");
// the container detects that userDAO has a dependency: name = "conn" and type = "Connection.class"
// where does it go to get the dependency to insert?