# PolymorphicDomainObjectContainer

API Documentation: | `PolymorphicDomainObjectContainer`

Known Subtypes: |
`TaskContainer`
`AuthenticationContainer`

A `NamedDomainObjectContainer` that allows you to create objects with different types.

### Properties

No properties

### Methods

Method | Description
`containerWithType(type)` | Creates a regular container that wraps the polymorphic container presenting all elements of a specified type.
`create(name)` | Creates a new item with the given name, adding it to this container.
`create(name, configureClosure)` | Creates a new item with the given name, adding it to this container, then configuring it with the given closure.
`create(name, type)` | Creates a domain object with the specified name and type, and adds it to the container.
`create(name, type, configuration)` | Creates a domain object with the specified name and type, adds it to the container, and configures it with the specified action.
`create(name, configureAction)` | Creates a new item with the given name, adding it to this container, then configuring it with the given action.
`getByName(name)` | Locates an object by name, failing if there is no such object.
`getByName(name, configureClosure)` | Locates an object by name, failing if there is no such object. The given configure closure is executed against the object before it is returned from this method. The object is passed to the closure as its delegate.
`getByName(name, configureAction)` | Locates an object by name, failing if there is no such object. The given configure action is executed against the object before it is returned from this method.
`maybeCreate(name)` | Looks for an item with the given name, creating and adding it to this container if it does not exist.
`maybeCreate(name, type)` | Looks for an item with the given name and type, creating and adding it to this container if it does not exist.
`named(name)` | Locates a object by name, failing if there is no such object.
`named(name, type)` | Locates a object by name and type, failing if there is no such object.
`named(name, type, configurationAction)` | Locates a object by name and type, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.
`named(name, configurationAction)` | Locates a object by name, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.
`named(nameFilter)` | Incubating Returns a collection containing the objects with names matching the provided filter. The returned collection is live, so that when matching objects are added to this collection, they are also visible in the filtered collection.
`register(name)` | Defines a new object, which will be created when it is required. A object is 'required' when the object is located using query methods such as `NamedDomainObjectCollection.getByName(java.lang.String)` or when `Provider.get()` is called on the return value of this method.
`register(name, configurationAction)` | Defines a new object, which will be created and configured when it is required. An object is 'required' when the object is located using query methods such as `NamedDomainObjectCollection.getByName(java.lang.String)` or when `Provider.get()` is called on the return value of this method.

### Script blocks

No script blocks

### Method details

#### ``NamedDomainObjectContainer`<`U`>` `containerWithType`(``Class`<`U`>` type)

Creates a regular container that wraps the polymorphic container presenting all elements of a specified type.

This method is an intermediate operation. It does not change the realized/unrealized state of the elements in the collection.

#### `T` `create`(`String` name)

Creates a new item with the given name, adding it to this container.

This operation is eager, the element is realized before being returned.

#### `T` `create`(`String` name, `Closure` configureClosure)

Creates a new item with the given name, adding it to this container, then configuring it with the given closure.

This operation is eager, the element is realized before being returned.

#### `U` `create`(`String` name, ``Class`<`U`>` type)

Creates a domain object with the specified name and type, and adds it to the container.

This operation is eager, the element is realized before being returned.

#### `U` `create`(`String` name, ``Class`<`U`>` type, ``Action`<? super `U`>` configuration)

Creates a domain object with the specified name and type, adds it to the container, and configures it with the specified action.

This operation is eager, the element is realized before being returned.

#### `T` `create`(`String` name, ``Action`<? super `T`>` configureAction)

Creates a new item with the given name, adding it to this container, then configuring it with the given action.

This operation is eager, the element is realized before being returned.

#### `T` `getByName`(`String` name)

Locates an object by name, failing if there is no such object.

This operation is eager and will cause the returned element to be realized.

#### `T` `getByName`(`String` name, `Closure` configureClosure)

Locates an object by name, failing if there is no such object. The given configure closure is executed against the object before it is returned from this method. The object is passed to the closure as its delegate.

This operation is eager and will cause the returned element to be realized.

#### `T` `getByName`(`String` name, ``Action`<? super `T`>` configureAction)

Locates an object by name, failing if there is no such object. The given configure action is executed against the object before it is returned from this method.

This operation is eager and will cause the returned element to be realized.

#### `T` `maybeCreate`(`String` name)

Looks for an item with the given name, creating and adding it to this container if it does not exist.

This operation is eager, the element is realized before being returned.

#### `U` `maybeCreate`(`String` name, ``Class`<`U`>` type)

Looks for an item with the given name and type, creating and adding it to this container if it does not exist.

This operation is eager, the element is realized before being returned.

#### ``NamedDomainObjectProvider`<`T`>` `named`(`String` name)

Locates a object by name, failing if there is no such object.

This method is lazy and will not cause the returned element to be realized.

#### ``NamedDomainObjectProvider`<`S`>` `named`(`String` name, ``Class`<`S`>` type)

Locates a object by name and type, failing if there is no such object.

This method is lazy and will not cause the returned element to be realized.

#### ``NamedDomainObjectProvider`<`S`>` `named`(`String` name, ``Class`<`S`>` type, ``Action`<? super `S`>` configurationAction)

Locates a object by name and type, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.

This method is lazy and will not cause the returned element to be realized.

#### ``NamedDomainObjectProvider`<`T`>` `named`(`String` name, ``Action`<? super `T`>` configurationAction)

Locates a object by name, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.

This method is lazy and will not cause the returned element to be realized.

#### ``NamedDomainObjectCollection`<`T`>` `named`(``Spec`<`String`>` nameFilter)

Note: This method is incubating and may change in a future version of Gradle.

Returns a collection containing the objects with names matching the provided filter. The returned collection is live, so that when matching objects are added to this collection, they are also visible in the filtered collection.

This method is an intermediate operation. It does not change the realized/unrealized state of the elements in the collection.

#### ``NamedDomainObjectProvider`<`T`>` `register`(`String` name)

Defines a new object, which will be created when it is required. A object is 'required' when the object is located using query methods such as `NamedDomainObjectCollection.getByName(java.lang.String)` or when `Provider.get()` is called on the return value of this method.

It is generally more efficient to use this method instead of `NamedDomainObjectContainer.create(java.lang.String)`, as that method will eagerly create the object, regardless of whether that object is required for the current build or not. This method, on the other hand, will defer creation until required.

This operation is lazy, the returned element is NOT realized. A `NamedDomainObjectProvider` is returned, allowing to continue to use it with other lazy APIs.

#### ``NamedDomainObjectProvider`<`T`>` `register`(`String` name, ``Action`<? super `T`>` configurationAction)

Defines a new object, which will be created and configured when it is required. An object is 'required' when the object is located using query methods such as `NamedDomainObjectCollection.getByName(java.lang.String)` or when `Provider.get()` is called on the return value of this method.

It is generally more efficient to use this method instead of `NamedDomainObjectContainer.create(java.lang.String, org.gradle.api.Action)` or `NamedDomainObjectContainer.create(java.lang.String)`, as those methods will eagerly create and configure the object, regardless of whether that object is required for the current build or not. This method, on the other hand, will defer creation and configuration until required.

This operation is lazy, the returned element is NOT realized. A `NamedDomainObjectProvider` is returned, allowing to continue to use it with other lazy APIs.