Struct CachedServiceRef<TService>
Caches a single service instance resolved through ServiceLocatorBridge.
Inherited Members
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; |
Returns
| Type | Description |
|---|---|
| bool |
|