Table of Contents

Class AppLocator

Namespace
Splat
Assembly
Splat.Core.dll

A Locator which will host the container for dependency injection based operations.

public static class AppLocator
Inheritance
AppLocator

Properties

Current

Gets 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 assigned on startup, a default, highly capable implementation will be used, and it is advised for most people to simply use the default implementation.

public static IReadonlyDependencyResolver Current { get; }

Property Value

IReadonlyDependencyResolver

The dependency resolver.

CurrentMutable

Gets 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 the default resolver.

public static IMutableDependencyResolver CurrentMutable { get; }

Property Value

IMutableDependencyResolver

Methods

AreResolverCallbackChangedNotificationsEnabled()

Indicates if the we are notifying external classes of updates to the resolver being changed.

public static bool AreResolverCallbackChangedNotificationsEnabled()

Returns

bool

A value indicating whether the notifications are happening.

GetLocator()

Gets the full locator. Note you should use Current or CurrentMutable in most situations.

public static IDependencyResolver GetLocator()

Returns

IDependencyResolver

The locator.

GetService<T>()

Gets an instance of the given service type. Must return null if the service is not available (must not throw).

public static T? GetService<T>()

Returns

T

The requested object, if found; null otherwise.

Type Parameters

T

The object type.

GetService<T>(string)

Gets an instance of the given service type. Must return null if the service is not available (must not throw).

public static T? GetService<T>(string contract)

Parameters

contract string

A value which will retrieve only a object registered with the same contract.

Returns

T

The requested object, if found; null otherwise.

Type Parameters

T

The object type.

GetServices<T>()

Gets all instances of the given service type. Must return an empty collection if the service is not available (must not return null or throw).

public static IEnumerable<T> GetServices<T>()

Returns

IEnumerable<T>

A sequence of instances of the requested service type. The sequence should be empty (not null) if no objects of the given type are available.

Type Parameters

T

The object type.

GetServices<T>(string)

Gets all instances of the given service type. Must return an empty collection if the service is not available (must not return null or throw).

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

Parameters

contract string

A value which will retrieve only objects registered with the same contract.

Returns

IEnumerable<T>

A sequence of instances of the requested service type. The sequence should be empty (not null) if no objects of the given type are available.

Type Parameters

T

The object type.

HasRegistration<T>()

Check to see if a resolver has a registration for a type.

public static bool HasRegistration<T>()

Returns

bool

Whether there is a registration for the type.

Type Parameters

T

The type to check for registration.

HasRegistration<T>(string)

Check to see if a resolver has a registration for a type.

public static bool HasRegistration<T>(string contract)

Parameters

contract string

A contract value which will indicates to only check for the registration if this contract is specified.

Returns

bool

Whether there is a registration for the type.

Type Parameters

T

The type to check for registration.

RegisterConstant<T>(T?)

Registers a constant value which will always return the specified object instance.

public static void RegisterConstant<T>(T? value) where T : class

Parameters

value T

The specified instance to always return.

Type Parameters

T

The service type to register for (must be a reference type).

RegisterConstant<T>(T?, string)

Registers a constant value which will always return the specified object instance.

public static void RegisterConstant<T>(T? value, string contract) where T : class

Parameters

value T

The specified instance to always return.

contract string

A contract value which will indicates to only return the value if this contract is specified.

Type Parameters

T

The service type to register for (must be a reference type).

RegisterLazySingleton<T>(Func<T?>)

Registers 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.

public static void RegisterLazySingleton<T>(Func<T?> valueFactory) where T : class

Parameters

valueFactory Func<T>

A factory method for generating a object of the specified type.

Type Parameters

T

The service type to register for (must be a reference type).

RegisterLazySingleton<T>(Func<T?>, string)

Registers 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.

public static void RegisterLazySingleton<T>(Func<T?> valueFactory, string contract) where T : class

Parameters

valueFactory Func<T>

A factory method for generating a object of the specified type.

contract string

A contract value which will indicates to only return the value if this contract is specified.

Type Parameters

T

The service type to register for (must be a reference type).

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

callback Action

A 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.

Register<T>(Func<T?>)

Register a function with the resolver which will generate an object for the specified service type.

public static void Register<T>(Func<T?> factory)

Parameters

factory Func<T>

The factory function which generates our object.

Type Parameters

T

The type which is used for the registration.

Register<T>(Func<T?>, string)

Register a function with the resolver which will generate an object for the specified service type.

public static void Register<T>(Func<T?> factory, string contract)

Parameters

factory Func<T>

The factory function which generates our object.

contract string

A contract value which will indicates to only generate the value if this contract is specified.

Type Parameters

T

The type which is used for the registration.

SetLocator(IDependencyResolver)

Allows setting the dependency resolver.

public static void SetLocator(IDependencyResolver dependencyResolver)

Parameters

dependencyResolver IDependencyResolver

The dependency resolver to set.

SuppressResolverCallbackChangedNotifications()

This method will prevent resolver changed notifications from happening until the returned IDisposable is disposed.

public static IDisposable SuppressResolverCallbackChangedNotifications()

Returns

IDisposable

A disposable which when disposed will indicate the change notification is no longer needed.

UnregisterAll<T>()

Unregisters the all the values for the specified type and the optional contract.

public static void UnregisterAll<T>()

Type Parameters

T

The type of items to unregister.

UnregisterAll<T>(string)

Unregisters the all the values for the specified type and the optional contract.

public static void UnregisterAll<T>(string contract)

Parameters

contract string

A contract which indicates to only removed those items registered with this contract.

Type Parameters

T

The type of items to unregister.

UnregisterCurrent<T>()

Unregisters the current the value for the specified type and the optional contract.

public static void UnregisterCurrent<T>()

Type Parameters

T

The type of item to unregister.

UnregisterCurrent<T>(string)

Unregisters the current the value for the specified type and the optional contract.

public static void UnregisterCurrent<T>(string contract)

Parameters

contract string

A contract which indicates to only removed the item registered with this contract.

Type Parameters

T

The type of item to unregister.