MentaContainer

Rev

Rev 4 | Rev 21 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 20
Line 6... Line 6...
6
 *   <li> Bean instantiation (duh!)</li>
6
 *   <li> Bean instantiation (duh!)</li>
7
 *   <li> Constructor injection for bean setup</li>
7
 *   <li> Constructor injection for bean setup</li>
8
 *   <li> Setter injection for bean setup</li>
8
 *   <li> Setter injection for bean setup</li>
9
 *   <li> Auto-wiring based on name and type</li>
9
 *   <li> Auto-wiring based on name and type</li>
10
 *   <li> Singleton</li>
10
 *   <li> Singleton</li>
11
 *   <li> Injection</li>
-
 
-
 
11
 *   <li> Wiring of external beans with the beans configured in this container</li>
12
 * </ul>
12
 * </ul>
13
 *
13
 *
14
 * It does not get much simpler than that.
14
 * It does not get much simpler than that.
15
 *
15
 *
16
 * @author sergio.oliveira.jr@gmail.com
16
 * @author sergio.oliveira.jr@gmail.com
Line 32... Line 32...
32
         * Configure a bean to be returned with the given implementation when {@link #get(String)} is called.
32
         * Configure a bean to be returned with the given implementation when {@link #get(String)} is called.
33
         *
33
         *
34
         * @param key The key representing the bean to return. The name of the bean in the container.
34
         * @param key The key representing the bean to return. The name of the bean in the container.
35
         * @param klass The class used to instantiate the bean, in other words, its implementation.
35
         * @param klass The class used to instantiate the bean, in other words, its implementation.
36
         * @param singleton A boolean to indicate if this bean will be a singleton.
36
         * @param singleton A boolean to indicate if this bean will be a singleton.
37
         * @return The container itself. (Fluent API)
-
 
-
 
37
         * @return The component created. (Fluent API)
38
         */
38
         */
39
        public Container ioc(String key, Class<? extends Object> klass, boolean singleton);
-
 
-
 
39
        public Component ioc(String key, Class<? extends Object> klass, boolean singleton);
40
       
40
       
41
        /**
41
        /**
42
         * Same as {@link #ioc(String, Class<? extends Object>, singleton)} except that it assumes
42
         * Same as {@link #ioc(String, Class<? extends Object>, singleton)} except that it assumes
43
         * singleton is false.
43
         * singleton is false.
44
         *
44
         *
45
         * @param key
45
         * @param key
46
         * @param klass
46
         * @param klass
47
         * @return The container itself. (Fluent API)
-
 
-
 
47
         * @return The component created. (Fluent API)
48
         */
48
         */
49
        public Container ioc(String key, Class<?extends Object> klass);
-
 
-
 
49
        public Component ioc(String key, Class<?extends Object> klass);
50
       
50
       
51
        /**
51
        /**
52
         * Configure a bean dependency to be auto-wired by the container. The dependency should be
-
 
53
         * an interface otherwise an exception is thrown. It works like that:
-
 
-
 
52
         * Set up IoC based on the component passed.
-
 
53
         *
-
 
54
         * @param component The component for the IoC.
-
 
55
         * @return The component passed as a parameter. (Fluent API)
-
 
56
         */
-
 
57
        public Component ioc(Component component);
-
 
58
       
-
 
59
        /**
-
 
60
         * Configure a bean dependency to be auto-wired by the container. In general you want the
-
 
61
         * type of the dependency to be an interface, for loosely couple dependencies. It works like that:<br/><br/>
54
         *
62
         *
55
         * Whenever the container returns a bean, it checks to see if it has a property named <i>property</i>
63
         * Whenever the container returns a bean, it checks to see if it has a property named <i>property</i>
56
         * and if the type of the property is <i>klass</i>. If it does, then it looks for a bean named
64
         * and if the type of the property is <i>klass</i>. If it does, then it looks for a bean named
57
         * <i>source</i> and injects it inside the first bean it is returning. This approach is recursive
65
         * <i>source</i> and injects it inside the first bean it is returning. This approach is recursive
58
         * so all properties are checked up the class hierarchy, until it reaches Object.
66
         * so all properties are checked up the class hierarchy, until it reaches Object.
59
         *
67
         *
60
         * @param property a bean property that will require another bean, in other words, the required
68
         * @param property a bean property that will require another bean, in other words, the required
61
         *                                 bean will be injected in the property of the bean been requested from the container. (auto-wiring by name)
69
         *                                 bean will be injected in the property of the bean been requested from the container. (auto-wiring by name)
62
         * @param klass an interface, not an implementation, defining the type of the auto-wiring. (auto-wiring by type)
-
 
-
 
70
         * @param klass the type of the dependency, in other words, the type of the auto-wiring. (auto-wiring by type)
63
         * @param source The dependency itself, coming from the container as well, in other words, the bean that will be injected in the original bean
71
         * @param source The dependency itself, coming from the container as well, in other words, the bean that will be injected in the original bean
64
         * @return The container itself. (Fluent API)
72
         * @return The container itself. (Fluent API)
65
         */
73
         */
66
        public Container autowire(String property, Class<? extends Object> klass, String source);
-
 
-
 
74
        public Dependency autowire(String property, Class<? extends Object> klass, String source);
67
       
75
       
68
        /**
76
        /**
69
         * Same as {@link #get(String)} except that it passes the property name as the source name, in other words,
-
 
-
 
77
         * Same as {@link #autowire(String, Class<? extends Object>)} except that it assumes that the property name will be the source name, in other words,
70
         * the property name is the same as the bean name that will be injected as the dependency.
78
         * the property name is the same as the bean name that will be injected as the dependency.
71
         *
79
         *
72
         * @param property
80
         * @param property
73
         * @param klass
81
         * @param klass
74
         * @return The container itself. (Fluent API)
82
         * @return The container itself. (Fluent API)
75
         */
83
         */
76
        public Container autowire(String property, Class<? extends Object> klass);
-
 
-
 
84
        public Dependency autowire(String property, Class<? extends Object> klass);
77
       
85
       
78
        /**
86
        /**
79
         * Add a constructor parameter that will be used by the container to instantiate the bean. The container keeps the order of the parameters
-
 
80
         * in case this method gets called more than once for the same bean, in other words, it assumes that the bean constructor takes more than
-
 
81
         * one parameter.
-
 
82
         *
87
         *
83
         * @param key The key representing the bean to return. The name of the bean in the container.
-
 
84
         * @param obj The constructor parameter value.
-
 
85
         * @return The container itself. (Fluent API)
-
 
86
         */
-
 
87
        public Container init(String key, Object obj);
-
 
88
       
-
 
89
        /**
-
 
90
         * Add a property that will be injected by the container in the bean it instantiates. To be not confused with auto-wiring. Here we are just passing
-
 
91
         * static values to be injected in the bean. Auto-wiring wires anything because it is based on interfaces and NOT on implementations.
-
 
92
         *
-
 
93
         * @param key The key representing the bean to return. The name of the bean in the container.
-
 
94
         * @param name The name of the bean property (bean must provide a property setter)
-
 
95
         * @param obj The value of the property that will be injected.
-
 
96
         * @return The container itself. (Fluent API)
-
 
97
         */
88
         */
98
        public Container set(String key, String name, Object obj);
-
 
-
 
89
        public Dependency autowire(Dependency dependency);
99
       
90
       
100
        /**
91
        /**
101
         * Take a given bean and populate its properties with other beans coming from this container. Perhaps you can call this auto-wiring.
92
         * Take a given bean and populate its properties with other beans coming from this container. Perhaps you can call this auto-wiring.
102
         * You basically checking properties of the given bean and looking for values (by name and type!) inside the container. And injecting
93
         * You basically checking properties of the given bean and looking for values (by name and type!) inside the container. And injecting
103
         * in the given bean, in other words, populating it.
94
         * in the given bean, in other words, populating it.