Table of Contents

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.

public interface IServiceLocator
Extension Methods
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>, bool)

Methods

AddLazySingleton<TContract>(Func<TContract>)

Registers a lazy singleton service using a factory function.

void AddLazySingleton<TContract>(Func<TContract> instanceFactory) where TContract : class

Parameters

instanceFactory Func<TContract>

The factory function that creates the service instance.

Type Parameters

TContract

The 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

instanceFactory Func<TContract>

The factory function that creates the service instance.

contract string

The contract name.

Type Parameters

TContract

The 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

instanceFactory Func<TContract>

The factory function that creates the service instance.

contract string

The contract name.

threadSafetyMode LazyThreadSafetyMode

The thread safety mode for the lazy instance.

Type Parameters

TContract

The 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

instanceFactory Func<TContract>

The factory function that creates the service instance.

threadSafetyMode LazyThreadSafetyMode

The thread safety mode for the lazy instance.

Type Parameters

TContract

The service type to register.

AddLazySingleton<TContract>(Lazy<TContract>)

Registers a lazy singleton service.

void AddLazySingleton<TContract>(Lazy<TContract> lazy) where TContract : class

Parameters

lazy Lazy<TContract>

The lazy service instance.

Type Parameters

TContract

The service type to register.

AddLazySingleton<TContract>(Lazy<TContract>, string)

Registers a lazy singleton service with a contract.

void AddLazySingleton<TContract>(Lazy<TContract> lazy, string contract) where TContract : class

Parameters

lazy Lazy<TContract>

The lazy service instance.

contract string

The contract name.

Type Parameters

TContract

The service type to register.

AddService<T>(Func<T>)

Registers a transient service using a factory function.

void AddService<T>(Func<T> instanceFactory)

Parameters

instanceFactory Func<T>

The factory function that creates the service instance.

Type Parameters

T

The service type to register.

AddService<T>(Func<T>, string)

Registers a transient service using a factory function with a contract.

void AddService<T>(Func<T> instanceFactory, string contract)

Parameters

instanceFactory Func<T>

The factory function that creates the service instance.

contract string

The contract name.

Type Parameters

T

The service type to register.

AddSingleton<TContract>(Func<TContract>)

Registers a singleton service using a factory function.

void AddSingleton<TContract>(Func<TContract> instanceFactory)

Parameters

instanceFactory Func<TContract>

The factory function that creates the service instance.

Type Parameters

TContract

The service type to register.

AddSingleton<TContract>(Func<TContract>, string)

Registers a singleton service using a factory function with a contract.

void AddSingleton<TContract>(Func<TContract> instanceFactory, string contract)

Parameters

instanceFactory Func<TContract>

The factory function that creates the service instance.

contract string

The contract name.

Type Parameters

TContract

The service type to register.

AddSingleton<TContract>(TContract)

Registers a singleton service instance.

void AddSingleton<TContract>(TContract instance) where TContract : class

Parameters

instance TContract

The service instance.

Type Parameters

TContract

The service type to register.

AddSingleton<TContract>(TContract, string)

Registers a singleton service instance with a contract.

void AddSingleton<TContract>(TContract instance, string contract) where TContract : class

Parameters

instance TContract

The service instance.

contract string

The contract name.

Type Parameters

TContract

The service type to register.

GetLazyService<T>()

Gets a lazy instance of the specified service type.

Lazy<T> GetLazyService<T>()

Returns

Lazy<T>

A lazy instance of the service.

Type Parameters

T

The service type to retrieve.

GetLazyService<T>(string)

Gets a lazy instance of the specified service type with a contract.

Lazy<T> GetLazyService<T>(string contract)

Parameters

contract string

The contract name.

Returns

Lazy<T>

A lazy instance of the service.

Type Parameters

T

The service type to retrieve.

GetService<T>()

Gets an instance of the specified service type.

T GetService<T>()

Returns

T

The service instance.

Type Parameters

T

The service type to retrieve.

Exceptions

InvalidOperationException

Thrown when the service is not registered.

GetService<T>(string)

Gets an instance of the specified service type with a contract.

T GetService<T>(string contract)

Parameters

contract string

The contract name.

Returns

T

The service instance.

Type Parameters

T

The service type to retrieve.

Exceptions

InvalidOperationException

Thrown when the service is not registered.

GetServices<T>()

Gets all instances of the specified service type.

IEnumerable<T> GetServices<T>()

Returns

IEnumerable<T>

A collection of service instances.

Type Parameters

T

The service type to retrieve.

GetServices<T>(string)

Gets all instances of the specified service type with a contract.

IEnumerable<T> GetServices<T>(string contract)

Parameters

contract string

The contract name.

Returns

IEnumerable<T>

A collection of service instances.

Type Parameters

T

The service type to retrieve.

HasService<T>()

Checks if a service of the specified type is registered.

bool HasService<T>()

Returns

bool

true if the service is registered; otherwise, false.

Type Parameters

T

The service type to check.

HasService<T>(string)

Checks if a service of the specified type with a contract is registered.

bool HasService<T>(string contract)

Parameters

contract string

The contract name.

Returns

bool

true if the service is registered; otherwise, false.

Type Parameters

T

The service type to check.

TryGetLazyService<T>(out Lazy<T>)

Tries to get a lazy instance of the specified service type.

bool TryGetLazyService<T>(out Lazy<T> service)

Parameters

service Lazy<T>

The lazy service instance if found; otherwise, null.

Returns

bool

true if the service was found; otherwise, false.

Type Parameters

T

The service type to retrieve.

TryGetLazyService<T>(string, out Lazy<T>)

Tries to get a lazy instance of the specified service type with a contract.

bool TryGetLazyService<T>(string contract, out Lazy<T> service)

Parameters

contract string

The contract name.

service Lazy<T>

The lazy service instance if found; otherwise, null.

Returns

bool

true if the service was found; otherwise, false.

Type Parameters

T

The service type to retrieve.

TryGetService<T>(string, out T)

Tries to get an instance of the specified service type with a contract.

bool TryGetService<T>(string contract, out T service)

Parameters

contract string

The contract name.

service T

The service instance if found; otherwise, the default value.

Returns

bool

true if the service was found; otherwise, false.

Type Parameters

T

The service type to retrieve.

TryGetService<T>(out T)

Tries to get an instance of the specified service type.

bool TryGetService<T>(out T service)

Parameters

service T

The service instance if found; otherwise, the default value.

Returns

bool

true if the service was found; otherwise, false.

Type Parameters

T

The service type to retrieve.