org.qi4j.api.object
Interface ObjectBuilder<T>

All Superinterfaces:
Iterable<T>

public interface ObjectBuilder<T>
extends Iterable<T>

From the ObjectBuilderFactory you can create ObjectBuilder instances. These are used to instantiate objects, i.e. instances of plain Java classes. You can either create a new instance using newInstance(), or perform dependency injection on an already available instance using injectTo(Object) (note that constructor injection will not be performed in this case), or you can use the builder for the prototype pattern by using it as an iterable, where each call to next() will create a new instance.


Method Summary
 void injectTo(T instance)
          Inject an existing instance.
 T newInstance()
          Creates a new instance from this ObjectBuilder.
 ObjectBuilder<T> use(Object... objects)
          Make the given objects available for @Uses injection.
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

use

ObjectBuilder<T> use(Object... objects)
Make the given objects available for @Uses injection.

These objects will be injected to the @Uses fields and arguments, when the object is created (constructor injection) or just has been created (field injection).

It is possible to provide more objects in the use() method than is actually required. Any additional objects will be discarded before the Application.activate() method is called, and eventually garbage collected.

Parameters:
objects - the objects to be used
Returns:
builder for objects

newInstance

T newInstance()
              throws ConstructionException
Creates a new instance from this ObjectBuilder.

Returns:
An object of type T.
Throws:
ConstructionException - If the object class is not compatible with the

injectTo

void injectTo(T instance)
              throws ConstructionException
Inject an existing instance. Only fields and methods will be called.

Parameters:
instance -
Throws:
ConstructionException