logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Struct CachedServiceRef<TService>

    Caches a single service instance resolved through ServiceLocatorBridge.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetType()
    Namespace: Serenity.Global.Application.Services
    Assembly: Serenity.Global.Application.dll
    Syntax
    public struct CachedServiceRef<TService> where TService : class
    Type Parameters
    Name Description
    TService

    The type of the service to resolve and cache.

    Remarks

    Replaces the hand-rolled "private field + resolved flag + TryGetX method" triple that otherwise gets repeated at every call site that needs a single cached service reference. Composition-edge only. If the caller can take a constructor parameter, take one.

    Methods

    GetOrNull()

    Returns the cached service, or null when it has not resolved yet.

    Declaration
    public TService GetOrNull()
    Returns
    Type Description
    TService

    Invalidate()

    Clears the cached resolution so the next call re-resolves through the locator.

    Declaration
    public void Invalidate()

    TryGet(out TService)

    Attempts to retrieve the cached service, resolving it through ServiceLocatorBridge the first time this succeeds.

    Declaration
    public bool TryGet(out TService service)
    Parameters
    Type Name Description
    TService service

    The service instance if resolved; null otherwise.

    Returns
    Type Description
    bool

    true if the service is cached or was just resolved; otherwise, false.

    In this article
    © 2026 Serenity. All Rights Reserved