logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    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

    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
    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
    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
    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(Type, out object)

    Attempts to retrieve the service registered for a type only known at runtime.

    Declaration
    bool TryGet(Type serviceType, out object service)
    Parameters
    Type Name Description
    Type serviceType

    The type of the service to retrieve.

    object service

    When this method returns, contains the service instance if found; otherwise, null.

    Returns
    Type Description
    bool

    true if a service of serviceType is registered; false when it is not, when serviceType is null, or when it is a value type (registration is constrained to reference types, so a value type can never resolve).

    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, 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.

    In this article
    © 2026 Serenity. All Rights Reserved