Class Locator
- Namespace
- Splat
- Assembly
- Splat.dll
Provides access to the application's dependency resolver and related functionality for service location and registration. This is now a wrapper around AppLocator which is the actual implementation.
public static class Locator
- Inheritance
-
Locator
Remarks
The Locator class exposes static members to retrieve or set the application's dependency resolver, as well as to register callbacks for resolver changes. Most applications should use the default resolver provided by this class. Advanced scenarios, such as library development or custom dependency resolution, may require interacting with the mutable resolver or registering for resolver change notifications.
Properties
Current
Gets the current dependency resolver used by the application.
public static IReadonlyDependencyResolver Current { get; }
Property Value
Remarks
Use this property to resolve application services and dependencies at runtime. The value is typically set during application startup and remains constant for the application's lifetime. If this isn't assigned on startup, a default, highly capable implementation will be used, and it is advised for most people to simply use the default implementation.
CurrentMutable
Gets the current mutable dependency resolver for the application.
public static IMutableDependencyResolver CurrentMutable { get; }
Property Value
Remarks
Use this property to register or override service implementations at runtime. Changes made to the resolver affect dependency resolution for the lifetime of the application. This property is typically used during application startup or for testing scenarios where services need to be replaced.
Methods
AreResolverCallbackChangedNotificationsEnabled()
Determines whether notifications are enabled when the resolver callback changes.
public static bool AreResolverCallbackChangedNotificationsEnabled()
Returns
- bool
true if resolver callback changed notifications are enabled; otherwise, false.
GetLocator()
Gets the full locator. Note you should use Current or CurrentMutable in most situations.
public static IDependencyResolver GetLocator()
Returns
- IDependencyResolver
The locator.
RegisterResolverCallbackChanged(Action)
This method allows libraries to register themselves to be set up whenever the dependency resolver changes. Applications should avoid this method, it is usually used for libraries that depend on service location.
public static IDisposable RegisterResolverCallbackChanged(Action callback)
Parameters
callbackActionA callback that is invoked when the resolver is changed. This callback is also invoked immediately, to configure the current resolver.
Returns
- IDisposable
When disposed, removes the callback. You probably can ignore this.
SetLocator(IDependencyResolver)
Sets the dependency resolver to be used by the application for resolving service dependencies.
public static void SetLocator(IDependencyResolver dependencyResolver)
Parameters
dependencyResolverIDependencyResolverThe dependency resolver instance that provides service resolution for the application. Cannot be null.
Remarks
Call this method during application startup to configure the global dependency resolution strategy. Subsequent service resolutions will use the specified resolver until it is replaced.
SuppressResolverCallbackChangedNotifications()
Temporarily suppresses notifications for resolver callback changes until the returned object is disposed.
public static IDisposable SuppressResolverCallbackChangedNotifications()
Returns
- IDisposable
An IDisposable that, when disposed, restores resolver callback change notifications.
Remarks
Use this method to prevent resolver callback change notifications from being raised during a batch of operations. Notifications will resume automatically when the returned object is disposed. This method is thread-safe.