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
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
TypeThe 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
TypeThe 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
TypeThe service type to remove.
ClearSingle(Type)
Removes a single-instance service type.
protected abstract void ClearSingle(Type serviceType)
Parameters
serviceType
TypeThe 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
TypeThe 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
TypeThe service type.
Returns
GetServiceInstances(Type)
Gets a mutable list of service instances of a specified type.
protected abstract List<object> GetServiceInstances(Type serviceType)
Parameters
serviceType
TypeThe service type.
Returns
GetServices(Type)
Gets a collection of service instanes of a specified type.
public abstract IEnumerable<object> GetServices(Type serviceType)
Parameters
serviceType
TypeThe 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
TypeThe service type.
index
intThe zero-based index at which the service should be inserted. If MaxValue is passed, ensures the element is added to the end.
service
objectThe 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
TypeThe service type.
index
intThe 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
Typetype 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
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
TypeThe 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
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
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
TypeThe type of service.
service
objectThe 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
TypeThe 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
ResetCache(Type)
Removes the cached values for a single service type.
protected virtual void ResetCache(Type serviceType)
Parameters
serviceType
TypeThe service type.