Class DependencyResolverMixins
- Namespace
- Splat
- Assembly
- Splat.dll
A set of extension methods that assist with the IDependencyResolver and IMutableDependencyResolver interfaces.
public static class DependencyResolverMixins
- Inheritance
-
DependencyResolverMixins
Methods
GetService<T>(IReadonlyDependencyResolver, string?)
Gets an instance of the given T
. Must return null
if the service is not available (must not throw).
public static T? GetService<T>(this IReadonlyDependencyResolver resolver, string? contract = null)
Parameters
resolver
IReadonlyDependencyResolverThe resolver we are getting the service from.
contract
stringA optional 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 type for the object we want to retrieve.
GetServices<T>(IReadonlyDependencyResolver, string?)
Gets all instances of the given T
. Must return an empty
collection if the service is not available (must not return null
or throw).
public static IEnumerable<T> GetServices<T>(this IReadonlyDependencyResolver resolver, string? contract = null)
Parameters
resolver
IReadonlyDependencyResolverThe resolver we are getting the service from.
contract
stringA optional value which will retrieve only a object registered with the same contract.
Returns
- IEnumerable<T>
A sequence of instances of the requested
T
. The sequence should be empty (notnull
) if no objects of the given type are available.
Type Parameters
T
The type for the object we want to retrieve.
RegisterConstant(IMutableDependencyResolver, object?, Type?, string?)
Registers a constant value which will always return the specified object instance.
public static void RegisterConstant(this IMutableDependencyResolver resolver, object? value, Type? serviceType, string? contract = null)
Parameters
resolver
IMutableDependencyResolverThe resolver to register the service type with.
value
objectThe specified instance to always return.
serviceType
TypeThe type of service to register.
contract
stringA optional contract value which will indicates to only return the value if this contract is specified.
RegisterConstant<T>(IMutableDependencyResolver, T?, string?)
Registers a constant value which will always return the specified object instance.
public static void RegisterConstant<T>(this IMutableDependencyResolver resolver, T? value, string? contract = null)
Parameters
resolver
IMutableDependencyResolverThe resolver to register the service type with.
value
TThe specified instance to always return.
contract
stringA optional contract value which will indicates to only return the value if this contract is specified.
Type Parameters
T
The service type to register for.
RegisterLazySingleton(IMutableDependencyResolver, Func<object?>, Type?, 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(this IMutableDependencyResolver resolver, Func<object?> valueFactory, Type? serviceType, string? contract = null)
Parameters
resolver
IMutableDependencyResolverThe resolver to register the service type with.
valueFactory
Func<object>A factory method for generating a object of the specified type.
serviceType
TypeThe type of service to register.
contract
stringA optional contract value which will indicates to only return the value if this contract is specified.
RegisterLazySingleton<T>(IMutableDependencyResolver, 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>(this IMutableDependencyResolver resolver, Func<T?> valueFactory, string? contract = null)
Parameters
resolver
IMutableDependencyResolverThe resolver to register the service type with.
valueFactory
Func<T>A factory method for generating a object of the specified type.
contract
stringA optional contract value which will indicates to only return the value if this contract is specified.
Type Parameters
T
The service type to register for.
Register<T>(IMutableDependencyResolver, Func<T?>, string?)
Registers a factory for the given T
.
public static void Register<T>(this IMutableDependencyResolver resolver, Func<T?> factory, string? contract = null)
Parameters
resolver
IMutableDependencyResolverThe resolver to register the service type with.
factory
Func<T>A factory method for generating a object of the specified type.
contract
stringA optional contract value which will indicates to only generate the value if this contract is specified.
Type Parameters
T
The service type to register for.
Register<TAs, T>(IMutableDependencyResolver, string?)
Registers a factory for the given T
.
public static void Register<TAs, T>(this IMutableDependencyResolver resolver, string? contract = null) where T : new()
Parameters
resolver
IMutableDependencyResolverThe resolver to register the service type with.
contract
stringA optional contract value which will indicates to only generate the value if this contract is specified.
Type Parameters
TAs
The type to register as.
T
The service type to register for.
ServiceRegistrationCallback(IMutableDependencyResolver, Type, Action<IDisposable>)
Registers a new callback that occurs when a new service with the specified type is registered.
public static IDisposable ServiceRegistrationCallback(this IMutableDependencyResolver resolver, Type serviceType, Action<IDisposable> callback)
Parameters
resolver
IMutableDependencyResolverThe resolver we want to register the callback with.
serviceType
TypeThe service type we are wanting to observe.
callback
Action<IDisposable>The callback which should be called.
Returns
- IDisposable
A disposable which will stop notifications to the callback.
UnregisterAll<T>(IMutableDependencyResolver, string?)
Unregisters the all the values for the specified type and the optional contract.
public static void UnregisterAll<T>(this IMutableDependencyResolver resolver, string? contract = null)
Parameters
resolver
IMutableDependencyResolverThe resolver to unregister the services with.
contract
stringA optional contract which indicates to only removed those items registered with this contract.
Type Parameters
T
The type of items to unregister.
UnregisterCurrent<T>(IMutableDependencyResolver, string?)
Unregisters the current the value for the specified type and the optional contract.
public static void UnregisterCurrent<T>(this IMutableDependencyResolver resolver, string? contract = null)
Parameters
resolver
IMutableDependencyResolverThe resolver to unregister the service with.
contract
stringA optional contract which indicates to only removed the item registered with this contract.
Type Parameters
T
The type of item to unregister.
WithResolver(IDependencyResolver, bool)
Override the default Dependency Resolver until the object returned is disposed.
public static IDisposable WithResolver(this IDependencyResolver resolver, bool suppressResolverCallback = true)
Parameters
resolver
IDependencyResolverThe test resolver to use.
suppressResolverCallback
boolIf we should suppress the resolver callback notify.
Returns
- IDisposable
A disposable which will reset the resolver back to the original.