IServiceLocator.TryGetLazyService(Lazy) method¶
Defined in
Type: IServiceLocator
Namespace: Splat
Assembly: Splat.Core.dll
Applies to
net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481, net471
Overloads¶
- 1.
bool TryGetLazyService<T>(out Lazy<T> service) - 2.
bool TryGetLazyService<T>(string contract, out Lazy<T> service)
1. Overload¶
bool TryGetLazyService<T>(out Lazy<T> service)
Summary: Attempts to retrieve a lazily initialized service of the specified type from the service provider.
Type parameters
| Name | Description |
|---|---|
T | The type of service to retrieve. Must have a public parameterless constructor. |
Parameters
| Name | Type | Description |
|---|---|---|
out service | Lazy | When this method returns, contains a Lazy instance for the requested service if found; otherwise, null. |
Returns: bool -- true if the service was found and assigned to the out parameter; otherwise, false.
2. Overload¶
bool TryGetLazyService<T>(string contract, out Lazy<T> service)
Summary: Attempts to retrieve a lazily initialized service of the specified type and contract.
Type parameters
| Name | Description |
|---|---|
T | The type of the service to retrieve. Must have a public parameterless constructor. |
Parameters
| Name | Type | Description |
|---|---|---|
contract | string | The contract name that uniquely identifies the requested service. Cannot be null. |
out service | Lazy | When this method returns, contains a Lazy instance for the requested service if found; otherwise, null. |
Returns: bool -- true if a matching service is found and assigned to the out parameter; otherwise, false.
Remarks
Use this method to attempt to obtain a service without throwing an exception if the service is not available. The service is created only when the Lazy is evaluated.