MentaContainer

Compare Revisions

Ignore whitespace Rev 4 → Rev 20

/trunk/src/main/java/org/mentacontainer/Container.java
8,7 → 8,7
* <li> Setter injection for bean setup</li>
* <li> Auto-wiring based on name and type</li>
* <li> Singleton</li>
* <li> Injection</li>
* <li> Wiring of external beans with the beans configured in this container</li>
* </ul>
*
* It does not get much simpler than that.
34,9 → 34,9
* @param key The key representing the bean to return. The name of the bean in the container.
* @param klass The class used to instantiate the bean, in other words, its implementation.
* @param singleton A boolean to indicate if this bean will be a singleton.
* @return The container itself. (Fluent API)
* @return The component created. (Fluent API)
*/
public Container ioc(String key, Class<? extends Object> klass, boolean singleton);
public Component ioc(String key, Class<? extends Object> klass, boolean singleton);
/**
* Same as {@link #ioc(String, Class<? extends Object>, singleton)} except that it assumes
44,14 → 44,22
*
* @param key
* @param klass
* @return The container itself. (Fluent API)
* @return The component created. (Fluent API)
*/
public Container ioc(String key, Class<?extends Object> klass);
public Component ioc(String key, Class<?extends Object> klass);
/**
* Configure a bean dependency to be auto-wired by the container. The dependency should be
* an interface otherwise an exception is thrown. It works like that:
* Set up IoC based on the component passed.
*
* @param component The component for the IoC.
* @return The component passed as a parameter. (Fluent API)
*/
public Component ioc(Component component);
/**
* Configure a bean dependency to be auto-wired by the container. In general you want the
* type of the dependency to be an interface, for loosely couple dependencies. It works like that:<br/><br/>
*
* Whenever the container returns a bean, it checks to see if it has a property named <i>property</i>
* and if the type of the property is <i>klass</i>. If it does, then it looks for a bean named
* <i>source</i> and injects it inside the first bean it is returning. This approach is recursive
59,45 → 67,28
*
* @param property a bean property that will require another bean, in other words, the required
* bean will be injected in the property of the bean been requested from the container. (auto-wiring by name)
* @param klass an interface, not an implementation, defining the type of the auto-wiring. (auto-wiring by type)
* @param klass the type of the dependency, in other words, the type of the auto-wiring. (auto-wiring by type)
* @param source The dependency itself, coming from the container as well, in other words, the bean that will be injected in the original bean
* @return The container itself. (Fluent API)
*/
public Container autowire(String property, Class<? extends Object> klass, String source);
public Dependency autowire(String property, Class<? extends Object> klass, String source);
/**
* Same as {@link #get(String)} except that it passes the property name as the source name, in other words,
* Same as {@link #autowire(String, Class<? extends Object>)} except that it assumes that the property name will be the source name, in other words,
* the property name is the same as the bean name that will be injected as the dependency.
*
* @param property
* @param klass
* @return The container itself. (Fluent API)
*/
public Container autowire(String property, Class<? extends Object> klass);
public Dependency autowire(String property, Class<? extends Object> klass);
/**
* Add a constructor parameter that will be used by the container to instantiate the bean. The container keeps the order of the parameters
* 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
* one parameter.
*
* @param key The key representing the bean to return. The name of the bean in the container.
* @param obj The constructor parameter value.
* @return The container itself. (Fluent API)
*/
public Container init(String key, Object obj);
public Dependency autowire(Dependency dependency);
/**
* 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
* static values to be injected in the bean. Auto-wiring wires anything because it is based on interfaces and NOT on implementations.
*
* @param key The key representing the bean to return. The name of the bean in the container.
* @param name The name of the bean property (bean must provide a property setter)
* @param obj The value of the property that will be injected.
* @return The container itself. (Fluent API)
*/
public Container set(String key, String name, Object obj);
/**
* Take a given bean and populate its properties with other beans coming from this container. Perhaps you can call this auto-wiring.
* You basically checking properties of the given bean and looking for values (by name and type!) inside the container. And injecting
* in the given bean, in other words, populating it.