IServiceLocator Interface
Provides the base requirements for an object that can store and provide services.
public interface IServiceLocator
Remarks
When calling the non-generic methods on this interface, the object key used to register the service should generally be a Type
instance.
Properties
SyncRoot
Gets an object that can be used to synchronize access to the services.
object SyncRoot { get; }
Property Value
- object:
An object that can be used to synchronize access to the services.
Methods
GetAllServiceTypes()
Returns a collection of all the service types that have been registered.
IEnumerable<object> GetAllServiceTypes()
Returns
- IEnumerable<object>:
A collection of all the service types that have been registered.
GetService(object)
Returns the service that has been registered with the specified type.
object GetService(object serviceType)
Parameter | Type | Description |
---|---|---|
serviceType | object | The type of service to return. |
Returns
- object:
The service that has been registered with the specified type.
GetService<T>()
Returns the service that has been registered with the specified type.
T GetService<T>()
- Type Parameters:
-
T
-The type of service to return.
Returns
- T:
The service that has been registered with the specified type.
RegisterService(object, object)
Registers a service instance for the specified service type.
void RegisterService(object serviceType, object service)
Parameter | Type | Description |
---|---|---|
serviceType | object | The type of service. |
service | object | The service object instance. |
RegisterService<T>(T)
Registers a service instance for the specified service type.
void RegisterService<T>(T service)
- Type Parameters:
-
T
-The type of service.
Parameter | Type | Description |
---|---|---|
service | T | The service object instance. |
UnregisterService(object)
Unregisters a service of the specified service type.
void UnregisterService(object serviceType)
Parameter | Type | Description |
---|---|---|
serviceType | object | The type of service. |
UnregisterService<T>()
Unregisters a service of the specified service type.
void UnregisterService<T>()
- Type Parameters:
-
T
-The type of service.
Events
ServiceAdded
Occurs after a service is added to the object.
event EventHandler<CollectionChangeEventArgs<object>> ServiceAdded
Event Type
ServiceRemoved
Occurs after a service is removed from the object.
event EventHandler<CollectionChangeEventArgs<object>> ServiceRemoved