Class AppLocator
- Namespace
- Splat
- Assembly
- Splat.Core.dll
A Locator which will host the container for dependency injection based operations.
- Inheritance
-
App
Locator
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.
Property Value
- IReadonly
Dependency Resolver 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.
Property Value
Methods
AreResolverCallbackChangedNotificationsEnabled()
Indicates if the we are notifying external classes of updates to the resolver being changed.
Returns
- bool
A value indicating whether the notifications are happening.
GetLocator()
Gets the full locator.
Note you should use Current or Current
Returns
- IDependency
Resolver The locator.
GetService<T>()
Gets an instance of the given service type. Must return null
if the service is not available (must not throw).
Returns
- T
The requested object, if found;
nullotherwise.
Type Parameters
TThe 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).
Parameters
contractstringA value which will retrieve only a object registered with the same contract.
Returns
- T
The requested object, if found;
nullotherwise.
Type Parameters
TThe 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).
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
TThe 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).
Parameters
contractstringA 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
TThe object type.
HasRegistration<T>()
Check to see if a resolver has a registration for a type.
Returns
- bool
Whether there is a registration for the type.
Type Parameters
TThe type to check for registration.
HasRegistration<T>(string)
Check to see if a resolver has a registration for a type.
Parameters
contractstringA 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
TThe type to check for registration.
RegisterConstant<T>(T?)
Registers a constant value which will always return the specified object instance.
Parameters
valueTThe specified instance to always return.
Type Parameters
TThe 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.
Parameters
valueTThe specified instance to always return.
contractstringA contract value which will indicates to only return the value if this contract is specified.
Type Parameters
TThe 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.
Parameters
valueFactoryFunc<T>A factory method for generating a object of the specified type.
Type Parameters
TThe 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.
Parameters
valueFactoryFunc<T>A factory method for generating a object of the specified type.
contractstringA contract value which will indicates to only return the value if this contract is specified.
Type Parameters
TThe 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.
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.
Register<T>(Func<T?>)
Register a function with the resolver which will generate an object for the specified service type.
Parameters
factoryFunc<T>The factory function which generates our object.
Type Parameters
TThe 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.
Parameters
factoryFunc<T>The factory function which generates our object.
contractstringA contract value which will indicates to only generate the value if this contract is specified.
Type Parameters
TThe type which is used for the registration.
SetLocator(IDependencyResolver)
Allows setting the dependency resolver.
Parameters
dependencyResolverIDependencyResolver The dependency resolver to set.
SuppressResolverCallbackChangedNotifications()
This method will prevent resolver changed notifications from happening until the returned IDisposable is disposed.
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.
Type Parameters
TThe type of items to unregister.
UnregisterAll<T>(string)
Unregisters the all the values for the specified type and the optional contract.
Parameters
contractstringA contract which indicates to only removed those items registered with this contract.
Type Parameters
TThe type of items to unregister.
UnregisterCurrent<T>()
Unregisters the current the value for the specified type and the optional contract.
Type Parameters
TThe type of item to unregister.
UnregisterCurrent<T>(string)
Unregisters the current the value for the specified type and the optional contract.
Parameters
contractstringA contract which indicates to only removed the item registered with this contract.
Type Parameters
TThe type of item to unregister.