Interface IServiceLocator
- Namespace
- Splat
- Assembly
- Splat.Core.dll
A generic-first service locator interface for AOT-friendly dependency resolution. This interface provides only generic methods to avoid reflection and support ahead-of-time compilation.
- Extension Methods
Methods
AddLazySingleton<TContract>(Func<TContract>)
Registers a lazy singleton service using a factory function.
Parameters
instanceFactoryFunc<TContract>The factory function that creates the service instance.
Type Parameters
TContractThe service type to register.
AddLazySingleton<TContract>(Func<TContract>, string)
Registers a lazy singleton service using a factory function with a contract.
void AddLazySingleton<TContract>(Func<TContract> instanceFactory, string contract) where TContract : class
Parameters
instanceFactoryFunc<TContract>The factory function that creates the service instance.
contractstringThe contract name.
Type Parameters
TContractThe service type to register.
AddLazySingleton<TContract>(Func<TContract>, string, LazyThreadSafetyMode)
Registers a lazy singleton service using a factory function with a contract.
void AddLazySingleton<TContract>(Func<TContract> instanceFactory, string contract, LazyThreadSafetyMode threadSafetyMode) where TContract : class
Parameters
instanceFactoryFunc<TContract>The factory function that creates the service instance.
contractstringThe contract name.
threadSafetyModeLazyThread Safety Mode The thread safety mode for the lazy instance.
Type Parameters
TContractThe service type to register.
AddLazySingleton<TContract>(Func<TContract>, LazyThreadSafetyMode)
Registers a lazy singleton service using a factory function.
void AddLazySingleton<TContract>(Func<TContract> instanceFactory, LazyThreadSafetyMode threadSafetyMode) where TContract : class
Parameters
instanceFactoryFunc<TContract>The factory function that creates the service instance.
threadSafetyModeLazyThread Safety Mode The thread safety mode for the lazy instance.
Type Parameters
TContractThe service type to register.
AddLazySingleton<TContract>(Lazy<TContract>)
Registers a lazy singleton service.
Parameters
lazyLazy<TContract>The lazy service instance.
Type Parameters
TContractThe service type to register.
AddLazySingleton<TContract>(Lazy<TContract>, string)
Registers a lazy singleton service with a contract.
Parameters
Type Parameters
TContractThe service type to register.
AddService<T>(Func<T>)
Registers a transient service using a factory function.
Parameters
instanceFactoryFunc<T>The factory function that creates the service instance.
Type Parameters
TThe service type to register.
AddService<T>(Func<T>, string)
Registers a transient service using a factory function with a contract.
Parameters
instanceFactoryFunc<T>The factory function that creates the service instance.
contractstringThe contract name.
Type Parameters
TThe service type to register.
AddSingleton<TContract>(Func<TContract>)
Registers a singleton service using a factory function.
Parameters
instanceFactoryFunc<TContract>The factory function that creates the service instance.
Type Parameters
TContractThe service type to register.
AddSingleton<TContract>(Func<TContract>, string)
Registers a singleton service using a factory function with a contract.
Parameters
instanceFactoryFunc<TContract>The factory function that creates the service instance.
contractstringThe contract name.
Type Parameters
TContractThe service type to register.
AddSingleton<TContract>(TContract)
Registers a singleton service instance.
Parameters
instanceTContractThe service instance.
Type Parameters
TContractThe service type to register.
AddSingleton<TContract>(TContract, string)
Registers a singleton service instance with a contract.
Parameters
instanceTContractThe service instance.
contractstringThe contract name.
Type Parameters
TContractThe service type to register.
GetLazyService<T>()
Gets a lazy instance of the specified service type.
Returns
- Lazy<T>
A lazy instance of the service.
Type Parameters
TThe service type to retrieve.
GetLazyService<T>(string)
Gets a lazy instance of the specified service type with a contract.
Parameters
contractstringThe contract name.
Returns
- Lazy<T>
A lazy instance of the service.
Type Parameters
TThe service type to retrieve.
GetService<T>()
Gets an instance of the specified service type.
Returns
- T
The service instance.
Type Parameters
TThe service type to retrieve.
Exceptions
- Invalid
Operation Exception Thrown when the service is not registered.
GetService<T>(string)
Gets an instance of the specified service type with a contract.
Parameters
contractstringThe contract name.
Returns
- T
The service instance.
Type Parameters
TThe service type to retrieve.
Exceptions
- Invalid
Operation Exception Thrown when the service is not registered.
GetServices<T>()
Gets all instances of the specified service type.
Returns
- IEnumerable<T>
A collection of service instances.
Type Parameters
TThe service type to retrieve.
GetServices<T>(string)
Gets all instances of the specified service type with a contract.
Parameters
contractstringThe contract name.
Returns
- IEnumerable<T>
A collection of service instances.
Type Parameters
TThe service type to retrieve.
HasService<T>()
Checks if a service of the specified type is registered.
Returns
- bool
trueif the service is registered; otherwise,false.
Type Parameters
TThe service type to check.
HasService<T>(string)
Checks if a service of the specified type with a contract is registered.
Parameters
contractstringThe contract name.
Returns
- bool
trueif the service is registered; otherwise,false.
Type Parameters
TThe service type to check.
TryGetLazyService<T>(out Lazy<T>)
Tries to get a lazy instance of the specified service type.
Parameters
serviceLazy<T>The lazy service instance if found; otherwise,
null.
Returns
- bool
trueif the service was found; otherwise,false.
Type Parameters
TThe service type to retrieve.
TryGetLazyService<T>(string, out Lazy<T>)
Tries to get a lazy instance of the specified service type with a contract.
Parameters
contractstringThe contract name.
serviceLazy<T>The lazy service instance if found; otherwise,
null.
Returns
- bool
trueif the service was found; otherwise,false.
Type Parameters
TThe service type to retrieve.
TryGetService<T>(string, out T)
Tries to get an instance of the specified service type with a contract.
Parameters
contractstringThe contract name.
serviceTThe service instance if found; otherwise, the default value.
Returns
- bool
trueif the service was found; otherwise,false.
Type Parameters
TThe service type to retrieve.
TryGetService<T>(out T)
Tries to get an instance of the specified service type.
Parameters
serviceTThe service instance if found; otherwise, the default value.
Returns
- bool
trueif the service was found; otherwise,false.
Type Parameters
TThe service type to retrieve.