Rev 40 | Rev 57 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 40 | Rev 41 | ||
---|---|---|---|
Line 19... | Line 19... | ||
19 | 19 | ||
20 | Container c = new MentaContainer(); |
20 | Container c = new MentaContainer(); |
21 | 21 | ||
22 | c.ioc("myString1", String.class); |
22 | c.ioc("myString1", String.class); |
23 | 23 | ||
24 | String myString1 = |
24 | String myString1 = c.get("myString1"); |
25 | 25 | ||
26 | System.out.println(myString1); // ==> "" ==> default constructor new String() was used |
26 | System.out.println(myString1); // ==> "" ==> default constructor new String() was used |
27 | 27 | ||
28 | c.ioc("myString2", String.class).addInitValue("saoj"); |
28 | c.ioc("myString2", String.class).addInitValue("saoj"); |
29 | 29 | ||
30 | String myString2 = |
30 | String myString2 = c.get("myString2"); |
31 | 31 | ||
32 | System.out.println(myString2); // ==> "saoj" ==> constructor new String("saoj") was used |
32 | System.out.println(myString2); // ==> "saoj" ==> constructor new String("saoj") was used |
33 | 33 | ||
34 | c.ioc("myDate1", Date.class).addProperty("hours", 15) // setHours(15) |
34 | c.ioc("myDate1", Date.class).addProperty("hours", 15) // setHours(15) |
35 | .addProperty("minutes", 10) // setMinutes(10) |
35 | .addProperty("minutes", 10) // setMinutes(10) |
36 | .addProperty("seconds", 45); // setSeconds(45) |
36 | .addProperty("seconds", 45); // setSeconds(45) |
37 | 37 | ||
38 | Date myDate1 = |
38 | Date myDate1 = c.get("myDate1"); |
39 | 39 | ||
40 | System.out.println(myDate1); // ==> a date with time 15:10:45 |
40 | System.out.println(myDate1); // ==> a date with time 15:10:45 |
41 | }
|
41 | }
|
42 | 42 | ||
43 | private static void case2() { |
43 | private static void case2() { |
44 | 44 | ||
45 | Container c = new MentaContainer(); |
45 | Container c = new MentaContainer(); |
46 | 46 | ||
47 | c.ioc("myString", String.class, true /* singleton */).addInitValue("saoj"); |
47 | c.ioc("myString", String.class, true /* singleton */).addInitValue("saoj"); |
48 | 48 | ||
49 | String s1 = |
49 | String s1 = c.get("myString"); |
50 | 50 | ||
51 | String s2 = |
51 | String s2 = c.get("myString"); |
52 | 52 | ||
53 | System.out.println(s1 == s2); // ==> true ==> same instance |
53 | System.out.println(s1 == s2); // ==> true ==> same instance |
54 | 54 | ||
55 | System.out.println(s1.equals(s2)); // ==> true => of course |
55 | System.out.println(s1.equals(s2)); // ==> true => of course |
56 | }
|
56 | }
|
Line 93... | Line 93... | ||
93 | // "conn" = the name of the property
|
93 | // "conn" = the name of the property
|
94 | // Connection.class = the type of the property
|
94 | // Connection.class = the type of the property
|
95 | // "connection" = the source from where the dependency will come from
|
95 | // "connection" = the source from where the dependency will come from
|
96 | c.autowire("conn", Connection.class, "connection"); |
96 | c.autowire("conn", Connection.class, "connection"); |
97 | 97 | ||
98 | UserDAO userDAO = |
98 | UserDAO userDAO = c.get("userDAO"); |
99 | 99 | ||
100 | // the container detects that userDAO has a dependency: name = "conn" and type = "Connection.class"
|
100 | // the container detects that userDAO has a dependency: name = "conn" and type = "Connection.class"
|
101 | // where does it go to get the dependency to insert?
|
101 | // where does it go to get the dependency to insert?
|
102 | // In itself: it does a Container.get("connection") => "connection" => the source
|
102 | // In itself: it does a Container.get("connection") => "connection" => the source
|
103 | 103 |