Table of Contents

Class ServicesContainer

Namespace
System.Web.Http.Controllers
Assembly
System.Web.Http.dll

An abstract class that provides a container for services used by ASP.NET Web API.

public abstract class ServicesContainer : IDisposable
Inheritance
ServicesContainer
Implements
Derived
Inherited Members

Constructors

ServicesContainer()

Initializes a new instance of the ServicesContainer class.

protected ServicesContainer()

Methods

Add(Type, object)

Adds a service to the end of services list for the given service type.

public void Add(Type serviceType, object service)

Parameters

serviceType Type

The service type.

service object

The service instance.

AddRange(Type, IEnumerable<object>)

Adds the services of the specified collection to the end of the services list for the given service type.

public void AddRange(Type serviceType, IEnumerable<object> services)

Parameters

serviceType Type

The service type.

services IEnumerable<object>

The services to add.

Clear(Type)

Removes all the service instances of the given service type.

public virtual void Clear(Type serviceType)

Parameters

serviceType Type

The service type to clear from the services list.

ClearMultiple(Type)

Removes all instances of a multi-instance service type.

protected virtual void ClearMultiple(Type serviceType)

Parameters

serviceType Type

The service type to remove.

ClearSingle(Type)

Removes a single-instance service type.

protected abstract void ClearSingle(Type serviceType)

Parameters

serviceType Type

The service type to remove.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public virtual void Dispose()

FindIndex(Type, Predicate<object>)

Searches for a service that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence.

public int FindIndex(Type serviceType, Predicate<object> match)

Parameters

serviceType Type

The service type.

match Predicate<object>

The delegate that defines the conditions of the element to search for.

Returns

int

The zero-based index of the first occurrence, if found; otherwise, -1.

GetService(Type)

Gets a service instance of a specified type.

public abstract object GetService(Type serviceType)

Parameters

serviceType Type

The service type.

Returns

object

GetServiceInstances(Type)

Gets a mutable list of service instances of a specified type.

protected abstract List<object> GetServiceInstances(Type serviceType)

Parameters

serviceType Type

The service type.

Returns

List<object>

A mutable list of service instances.

GetServices(Type)

Gets a collection of service instanes of a specified type.

public abstract IEnumerable<object> GetServices(Type serviceType)

Parameters

serviceType Type

The service type.

Returns

IEnumerable<object>

A collection of service instances.

Insert(Type, int, object)

Inserts a service into the collection at the specified index.

public void Insert(Type serviceType, int index, object service)

Parameters

serviceType Type

The service type.

index int

The zero-based index at which the service should be inserted. If MaxValue is passed, ensures the element is added to the end.

service object

The service to insert.

InsertRange(Type, int, IEnumerable<object>)

Inserts the elements of the collection into the service list at the specified index.

public void InsertRange(Type serviceType, int index, IEnumerable<object> services)

Parameters

serviceType Type

The service type.

index int

The zero-based index at which the new elements should be inserted. If MaxValue is passed, ensures the elements are added to the end.

services IEnumerable<object>

The collection of services to insert.

IsSingleService(Type)

Determine whether the service type should be fetched with GetService or GetServices.

public abstract bool IsSingleService(Type serviceType)

Parameters

serviceType Type

type of service to query

Returns

bool

true iff the service is singular.

Remove(Type, object)

Removes the first occurrence of the given service from the service list for the given service type.

public bool Remove(Type serviceType, object service)

Parameters

serviceType Type

The service type.

service object

The service instance to remove.

Returns

bool

true if the item is successfully removed; otherwise, false.

RemoveAll(Type, Predicate<object>)

Removes all the elements that match the conditions defined by the specified predicate.

public int RemoveAll(Type serviceType, Predicate<object> match)

Parameters

serviceType Type

The service type.

match Predicate<object>

The delegate that defines the conditions of the elements to remove.

Returns

int

The number of elements removed from the list.

RemoveAt(Type, int)

Removes the service at the specified index.

public void RemoveAt(Type serviceType, int index)

Parameters

serviceType Type

The service type.

index int

The zero-based index of the service to remove.

Replace(Type, object)

Replaces all existing services for the given service type with the given service instance. This works for both singular and plural services.

public void Replace(Type serviceType, object service)

Parameters

serviceType Type

The service type.

service object

The service instance.

ReplaceMultiple(Type, object)

Replaces all instances of a multi-instance service with a new instance.

protected virtual void ReplaceMultiple(Type serviceType, object service)

Parameters

serviceType Type

The type of service.

service object

The service instance that will replace the current services of this type.

ReplaceRange(Type, IEnumerable<object>)

Replaces all existing services for the given service type with the given service instances.

public void ReplaceRange(Type serviceType, IEnumerable<object> services)

Parameters

serviceType Type

The service type.

services IEnumerable<object>

The service instances.

ReplaceSingle(Type, object)

Replaces a single-instance service of a specified type.

protected abstract void ReplaceSingle(Type serviceType, object service)

Parameters

serviceType Type

The service type.

service object

The service instance.

ResetCache(Type)

Removes the cached values for a single service type.

protected virtual void ResetCache(Type serviceType)

Parameters

serviceType Type

The service type.