Class MicrosoftDependencyResolver
- Namespace
- Splat.Microsoft.Extensions.Dependency
Injection
- Assembly
- Splat.Microsoft.Extensions.DependencyInjection.dll
Microsoft DI implementation for Splat.
public class MicrosoftDependencyResolver : IDependencyResolver, IReadonlyDependencyResolver, IMutableDependencyResolver, IDisposable, IAsyncDisposable
- Inheritance
-
Microsoft
Dependency Resolver
- Implements
-
IDependency
Resolver IReadonlyDependency Resolver IMutableDependency Resolver
- Extension Methods
Constructors
MicrosoftDependencyResolver(IServiceCollection?)
Initializes a new instance of the Microsoft
Parameters
servicesIServiceCollection An instance of IService
Collection .
MicrosoftDependencyResolver(IServiceProvider)
Initializes a new instance of the Microsoft
Parameters
serviceProviderIServiceProvider A ready to use service provider.
Properties
ServiceProvider
Gets the internal Microsoft container, or builds a new one if this instance was not initialized with one.
Property Value
Methods
Dispose()
Dispose(bool)
Disposes of the instance.
Parameters
disposingboolWhether or not the instance is disposing.
DisposeAsync()
Returns
GetService(Type?, string?)
Gets an instance of the given serviceType. Must return null
if the service is not available (must not throw).
Parameters
serviceTypeTypeThe object type.
contractstringAn optional value which will retrieve only a object registered with the same contract.
Returns
- object
The requested object, if found;
nullotherwise.
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).
Parameters
serviceTypeTypeThe object type.
contractstringAn optional 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.
HasRegistration(Type?, string?)
Check to see if a resolver has a registration for a type.
Parameters
serviceTypeTypeThe type to check for registration.
contractstringAn optional contract value which will indicates to only generate the value if this contract is specified.
Returns
- bool
Whether there is a registration for the type.
Register(Func<object?>, Type?, string?)
Register a function with the resolver which will generate an object for the specified service type. Optionally a contract can be registered which will indicate that registration will only work with that contract. Most implementations will use a stack based approach to allow for multiple items to be registered.
Parameters
factoryFunc<object>The factory function which generates our object.
serviceTypeTypeThe type which is used for the registration.
contractstringAn optional contract value which will indicates to only generate the value if this contract is specified.
ServiceRegistrationCallback(Type, string?, Action<IDisposable>)
Register a callback to be called when a new service matching the type and contract is registered.
When registered, the callback is also called for each currently matching service.
public virtual IDisposable ServiceRegistrationCallback(Type serviceType, string? contract, Action<IDisposable> callback)
Parameters
serviceTypeTypeThe type which is used for the registration.
contractstringAn optional contract value which will indicates to only generate the value if this contract is specified.
callbackAction<IDisposable>The callback which will be called when the specified service type and contract are registered.
Returns
- IDisposable
When disposed removes the callback.
UnregisterAll(Type?, string?)
Unregisters all the values associated with the specified type and contract - or -
If the container has already been built, removes the specified contract (scope) entirely,
ignoring the serviceType argument.
Parameters
serviceTypeTypeThe service type to unregister.
contractstringAn optional value which will remove only an object registered with the same contract.
UnregisterCurrent(Type?, string?)
Unregisters the current item based on the specified type and contract.
Parameters
serviceTypeTypeThe service type to unregister.
contractstringThe optional contract value, which will only remove the value associated with the contract.
UpdateContainer(IServiceCollection)
Updates this instance with a collection of configured services.
Parameters
servicesIServiceCollection An instance of IService
Collection .
UpdateContainer(IServiceProvider)
Updates this instance with a configured service Provider.
Parameters
serviceProviderIServiceProvider A ready to use service provider.