@Incubating public interface ObjectFactory
An instance of the factory can be injected into a task or plugin by annotating a public constructor or method with javax.inject.Inject
. It is also available via Project.getObjects()
.
Modifier and Type | Method and Description |
---|---|
<T extends Named> |
named(Class<T> type,
String name)
Creates a simple immutable
Named object of the given type and name. |
<T> T |
newInstance(Class<? extends T> type,
Object... parameters)
Create a new instance of T, using
parameters as the construction parameters. |
<T extends Named> T named(Class<T> type, String name) throws ObjectInstantiationException
Named
object of the given type and name.
The given type can be an interface that extends Named
or an abstract class that 'implements' Named
. An abstract class, if provided:
Named.getName()
and should define this method as abstract. Any implementation will be overridden.An interface, if provided, must not define or inherit any other methods.
Objects created using this method are not decorated or extensible.
ObjectInstantiationException
- On failure to create the new instance.<T> T newInstance(Class<? extends T> type, Object... parameters) throws ObjectInstantiationException
parameters
as the construction parameters.
The type must be a non-abstract class.
Objects created using this method are decorated and extensible, meaning that they have DSL support mixed in and can be extended using the `extensions` property, similar to the Project
object.
An @Inject annotation is required on any constructor that accepts parameters because JSR-330 semantics for dependency injection are used. In addition to those parameters provided as an argument to this method, the following services are also available for injection:
ObjectInstantiationException
- On failure to create the new instance.