Interface IServiceLocator
Contract for a service locator that provides runtime access to registered services by type.
Namespace: Serenity.ServiceLocator.Application.Interfaces
Assembly: Serenity.Global.Application.dll
Syntax
public interface IServiceLocator
Methods
Contains<T>()
Determines whether a service of the specified type is registered.
Declaration
bool Contains<T>() where T : class
Returns
| Type | Description |
|---|---|
| bool |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the service to check. |
Get<T>()
Retrieves the service registered for the specified type.
Declaration
T Get<T>() where T : class
Returns
| Type | Description |
|---|---|
| T | The registered service instance. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the service to retrieve. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when no service of type |
Register<T>(T)
Registers a service instance for the specified type.
Declaration
void Register<T>(T service) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | service | The service instance to register. Must not be null. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to register the service as. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| InvalidOperationException | Thrown when a service of type |
Remove<T>()
Removes the service registered for the specified type.
Declaration
void Remove<T>() where T : class
Type Parameters
| Name | Description |
|---|---|
| T | The type of the service to remove. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when no service of type |
TryGet<T>(out T)
Attempts to retrieve the service registered for the specified type.
Declaration
bool TryGet<T>(out T service) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | service | When this method returns, contains the service instance if found; otherwise, |
Returns
| Type | Description |
|---|---|
| bool |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of the service to retrieve. |