Skip to content

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

NameSummary
GetServiceGets an instance of the specified service type.
GetServicesGets all registered service instances of the specified type.
TryGetServiceAttempts to retrieve a service object of the specified type from the service provider.
GetLazyServiceRetrieves a lazily initialized instance of the specified service type from the dependency injection container.
TryGetLazyServiceAttempts to retrieve a lazily initialized service of the specified type from the service provider.
HasServiceDetermines whether a service of the specified type is available from the service provider.
AddServiceRegisters a transient service of the specified type using the provided factory function.
AddSingletonRegisters the specified instance as a singleton service for the given contract type.
AddLazySingletonRegisters a lazily initialized singleton instance for the specified contract type.