IServiceLocator interface¶
Defined in
Namespace: Splat
Assembly: Splat.Core.dll
Full name: Splat.IServiceLocator
Modifiers: public abstract
Summary¶
Defines a contract for registering, retrieving, and managing service instances by type and optional contract name.
Enables dependency resolution and service location within an application or component.
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
Remarks¶
The IServiceLocator interface provides methods for registering services as singletons, transients, or lazy singletons, and for retrieving them by type or by type and contract name. It supports both direct retrieval and safe, non-throwing attempts to resolve services. This interface is commonly used to decouple service consumers from concrete implementations and to facilitate dependency injection patterns. Thread safety and lifetime management depend on the specific implementation of the interface.
Methods¶
| Name | Summary |
|---|---|
| GetService | Gets an instance of the specified service type. |
| GetServices | Gets all registered service instances of the specified type. |
| TryGetService | Attempts to retrieve a service object of the specified type from the service provider. |
| GetLazyService | Retrieves a lazily initialized instance of the specified service type from the dependency injection container. |
| TryGetLazyService | Attempts to retrieve a lazily initialized service of the specified type from the service provider. |
| HasService | Determines whether a service of the specified type is available from the service provider. |
| AddService | Registers a transient service of the specified type using the provided factory function. |
| AddSingleton | Registers the specified instance as a singleton service for the given contract type. |
| AddLazySingleton | Registers a lazily initialized singleton instance for the specified contract type. |