logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class DefaultServiceLocator

    Default implementation of IServiceLocator. Stores service instances by type in a dictionary.

    Inheritance
    object
    DefaultServiceLocator
    Implements
    IServiceLocator
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.ServiceLocator.Application.Services
    Assembly: Serenity.Global.Application.dll
    Syntax
    public class DefaultServiceLocator : IServiceLocator

    Constructors

    DefaultServiceLocator()

    Declaration
    public DefaultServiceLocator()

    Methods

    Contains<T>()

    Determines whether a service of the specified type is registered.

    Declaration
    public bool Contains<T>() where T : class
    Returns
    Type Description
    bool

    true if a service of type T is registered; otherwise, false.

    Type Parameters
    Name Description
    T

    The type of the service to check.

    Get<T>()

    Retrieves the service registered for the specified type.

    Declaration
    public 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 T is registered.

    Register<T>(T)

    Registers a service instance for the specified type.

    Declaration
    public 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 service is null.

    InvalidOperationException

    Thrown when a service of type T is already registered.

    Remove<T>()

    Removes the service registered for the specified type.

    Declaration
    public 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 T is registered.

    TryGet<T>(out T)

    Attempts to retrieve the service registered for the specified type.

    Declaration
    public 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, null.

    Returns
    Type Description
    bool

    true if a service of type T is registered; otherwise, false.

    Type Parameters
    Name Description
    T

    The type of the service to retrieve.

    Implements

    IServiceLocator
    In this article
    © 2026 Serenity. All Rights Reserved