Skip to content

AppLocator class

Defined in

Namespace: Splat Assembly: Splat.Core.dll Full name: Splat.AppLocator Modifiers: public static

Summary

View source

        Provides a global access point for dependency resolution within the application, allowing services and types to be
        registered and retrieved at runtime.
        

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

AppLocator exposes static members for resolving and registering dependencies using a default or custom dependency resolver. It is intended for use by both application code and libraries that require service location. In most scenarios, the default resolver is sufficient and should be used unless advanced customization or testing scenarios require replacing it. Thread safety and resolver change notifications are managed internally. For most applications, use the Current and CurrentMutable properties to access the dependency resolver.

Properties

NameSummary
static CurrentGets the read only dependency resolver. This class is used throughout libraries for many internal operations as well as for general use by applications. If this isn't...
static CurrentMutableGets the mutable dependency resolver. The default resolver is also a mutable resolver, so this will be non-null. Use this to register new types on startup if you are using...

Methods

NameSummary
static RegisterResolverInitializerRegisters the action that initializes each resolver as it is set or reset for the application.
static SetLocatorSets the dependency resolver to be used by the application.
static GetLocatorGets the current dependency resolver instance used by the application.
static RegisterResolverCallbackChangedThis 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...
static SuppressResolverCallbackChangedNotificationsThis method will prevent resolver changed notifications from happening until the returned IDisposable is disposed.
static AreResolverCallbackChangedNotificationsEnabledIndicates if the we are notifying external classes of updates to the resolver being changed.
static GetServiceGets an instance of the given service type. Must return null if the service is not available (must not throw).
static GetServicesGets all instances of the given service type. Must return an empty collection if the service is not available (must not return null or throw).
static HasRegistrationCheck to see if a resolver has a registration for a type.
static RegisterRegister a function with the resolver which will generate an object for the specified service type.
static RegisterConstantRegisters a constant value which will always return the specified object instance.
static RegisterLazySingletonRegisters a lazy singleton value which will always return the specified object instance once created. The value is only generated once someone requests the service from the resolver.
static UnregisterCurrentUnregisters the current the value for the specified type and the optional contract.
static UnregisterAllUnregisters the all the values for the specified type and the optional contract.
Inherited members