Interface IReadonlyDependencyResolver
- Namespace
- Splat
- Assembly
- Splat.Core.dll
Defines a read-only contract for resolving service instances and collections by type and optional contract identifier.
public interface IReadonlyDependencyResolver
- Extension Methods
Remarks
This interface provides methods to retrieve single or multiple service instances from a dependency resolver without allowing registration or modification of services. Implementations must not throw exceptions or return null when a service is unavailable; instead, they should return null for single-instance methods and an empty collection for multi-instance methods. This interface is typically used to access services in a decoupled manner, supporting scenarios such as dependency injection, plugin architectures, or service location patterns.
Methods
GetService(Type?)
Gets an instance of the given serviceType. Must return null
if the service is not available (must not throw).
object? GetService(Type? serviceType)
Parameters
serviceTypeTypeThe object type.
Returns
- object
The requested object, if found;
nullotherwise.
GetService(Type?, string?)
Gets an instance of the given serviceType. Must return null
if the service is not available (must not throw).
object? GetService(Type? serviceType, string? contract)
Parameters
serviceTypeTypeThe object type.
contractstringA value which will retrieve only a object registered with the same contract.
Returns
- object
The requested object, if found;
nullotherwise.
GetService<T>()
Gets an instance of the given T. Must return null
if the service is not available (must not throw).
T? GetService<T>()
Returns
- T
The requested object, if found;
nullotherwise.
Type Parameters
TThe object type.
GetService<T>(string?)
Gets an instance of the given T. Must return null
if the service is not available (must not throw).
T? GetService<T>(string? contract)
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(Type?)
Gets all instances of the given serviceType. Must return an empty
collection if the service is not available (must not return null or throw).
IEnumerable<object> GetServices(Type? serviceType)
Parameters
serviceTypeTypeThe object type.
Returns
- IEnumerable<object>
A sequence of instances of the requested
serviceType. The sequence should be empty (notnull) if no objects of the given type are available.
GetServices(Type?, string?)
Gets all instances of the given serviceType. Must return an empty
collection if the service is not available (must not return null or throw).
IEnumerable<object> GetServices(Type? serviceType, string? contract)
Parameters
serviceTypeTypeThe object type.
contractstringA value which will retrieve only objects registered with the same contract.
Returns
- IEnumerable<object>
A sequence of instances of the requested
serviceType. The sequence should be empty (notnull) if no objects of the given type are available.
GetServices<T>()
Gets all instances of the given T. Must return an empty
collection if the service is not available (must not return null or throw).
IEnumerable<T> GetServices<T>()
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
TThe object type.
GetServices<T>(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).
IEnumerable<T> GetServices<T>(string? contract)
Parameters
contractstringA value which will retrieve only objects 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
TThe object type.