Skip to main content

Class ServiceCollection

Represents a collection of services and provides methods to manage and retrieve services from the collection.

Assembly: Meadow.Contracts.dll
View Source
Declaration
public class ServiceCollection : IEnumerable<object>, IEnumerable

Implements:
System.Collections.Generic.IEnumerable<System.Object>, System.Collections.IEnumerable

Methods

GetEnumerator()

Returns an enumerator that iterates through the collection of services.

View Source
Declaration
public IEnumerator<object> GetEnumerator()
Returns

System.Collections.Generic.IEnumerator<System.Object>: An enumerator that can be used to iterate through the collection.### Add(object) Adds a service to the collection.

View Source
Declaration
public void Add(object o)
Parameters
TypeNameDescription
System.ObjectoThe service object to add.

Add(object, Type)

Adds a service to the collection and registers it with the specified type.

View Source
Declaration
public void Add(object o, Type registerAs)
Parameters
TypeNameDescription
System.ObjectoThe service object to add.
System.TyperegisterAsThe type to register the service as.

ContainsRegisteredType<TRegisteredType>()

Determines whether the collection contains a service of the specified registered type.

View Source
Declaration
public bool ContainsRegisteredType<TRegisteredType>()
Returns

System.Boolean: true if the collection contains the service; otherwise, false.##### Type Parameters | Name | Description | |:--- |:--- | | TRegisteredType | The registered type of the service. |

Add<TRegisterAs>(TRegisterAs)

Adds a service to the collection and registers it with the specified type.

View Source
Declaration
public void Add<TRegisterAs>(TRegisterAs o)
Parameters
TypeNameDescription
<TRegisterAs>oThe service object to add.
Type Parameters
NameDescription
TRegisterAsThe type to register the service as.

Get(Type)

Gets a service of the specified registered type from the collection.

View Source
Declaration
public object? Get(Type registeredType)
Returns

System.Object: The service object if found; otherwise, null.

Parameters
TypeNameDescription
System.TyperegisteredTypeThe registered type of the service to retrieve.

Get<TRegisteredType>()

Gets a service of the specified registered type from the collection.

View Source
Declaration
public TRegisteredType? Get<TRegisteredType>()
Returns

<TRegisteredType>: The service object if found; otherwise, null.##### Type Parameters | Name | Description | |:--- |:--- | | TRegisteredType | The registered type of the service to retrieve. |

GetOrCreate<TCreateType>()

Gets or creates a service of the specified type from the collection. If the service does not exist, a new instance of the specified type is created and added to the collection.

View Source
Declaration
public TCreateType GetOrCreate<TCreateType>()
Returns

<TCreateType>: The service object of the specified type.##### Type Parameters | Name | Description | |:--- |:--- | | TCreateType | The type of the service to create or retrieve. |

GetOrCreate<TCreateType, TRegisteredType>()

Gets or creates a service of the specified creation type and registered type from the collection. If the service does not exist, a new instance of the creation type is created and added to the collection and registered with the specified registered type.

View Source
Declaration
public TRegisteredType GetOrCreate<TCreateType, TRegisteredType>() where TCreateType : TRegisteredType
Returns

<TRegisteredType>: The service object of the specified creation type and registered type.##### Type Parameters | Name | Description | |:--- |:--- | | TCreateType | The type of the service to create. | | TRegisteredType | The type to register the service as. |

Create<TCreateType>()

Creates and adds a service of the specified type to the collection.

View Source
Declaration
public TCreateType Create<TCreateType>()
Returns

<TCreateType>: The created service object.##### Type Parameters | Name | Description | |:--- |:--- | | TCreateType | The type of the service to create. |

Create<TCreateType, TRegisterAs>()

Creates and adds a service of the specified creation type and registered type to the collection.

View Source
Declaration
public TCreateType Create<TCreateType, TRegisterAs>() where TCreateType : TRegisterAs
Returns

<TCreateType>: The created service object.##### Type Parameters | Name | Description | |:--- |:--- | | TCreateType | The type of the service to create. | | TRegisterAs | The type to register the service as. |

Create(Type)

Creates and adds a service of the specified type to the collection.

View Source
Declaration
public object Create(Type createType)
Returns

System.Object: The created service object.

Parameters
TypeNameDescription
System.TypecreateTypeThe type of the service to create.

Create(Type, Type?)

Creates and adds a service of the specified type to the collection.

View Source
Declaration
public object Create(Type createType, Type? registerType)
Returns

System.Object: The created service object.

Parameters
TypeNameDescription
System.TypecreateTypeThe type of the service to create.
System.TyperegisterTypeThe type to register the service as.

GenerateInstance(Type)

Creates an instance of the requested type, including any constructor or property injections

View Source
Declaration
public object GenerateInstance(Type createType)
Returns

System.Object: An instance of the requested type

Parameters
TypeNameDescription
System.TypecreateTypeThe type of the object to create

Implements

  • System.Collections.Generic.IEnumerable<System.Object>
  • System.Collections.IEnumerable

Extension Methods

  • System.Collections.Generic.IEnumerable{System.Object}.Meadow.ExtensionMethods.Contains``1(System.Object[])
  • System.Collections.Generic.IEnumerable{System.Object}.Meadow.ExtensionMethods.FirstIndexOf``1(System.Object[])