Skip to content

MicrosoftDependencyResolver class

Defined in

Namespace: Splat.Microsoft.Extensions.DependencyInjection Assembly: Splat.Microsoft.Extensions.DependencyInjection.dll Full name: Splat.Microsoft.Extensions.DependencyInjection.MicrosoftDependencyResolver Modifiers: public

Summary

View source

        Provides an implementation of the dependency resolver pattern using Microsoft.Extensions.DependencyInjection.
        Supports registration, resolution, and management of services with optional contract-based (keyed) registrations.
        

Applies to

net10.0, net10.0-desktop1.0, net10.0-browserwasm1.0, net9.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0, net8.0-ios17.5, net8.0-macos14.5, net8.0-macos14.5, net8.0-macos14.2, net8.0-macos14.2, net8.0-maccatalyst17.5, net8.0-maccatalyst17.5, net8.0-tvos17.2, net8.0-tvos17.2, net8.0-ios17.5, netstandard2.1, netstandard2.1, netstandard2.0, netstandard2.0, net481, net462

Class hierarchy
classDiagram
class MicrosoftDependencyResolver
class IDependencyResolver {
    <>
}
IDependencyResolver <|.. MicrosoftDependencyResolver
class IReadonlyDependencyResolver {
    <>
}
IReadonlyDependencyResolver <|.. MicrosoftDependencyResolver
class IMutableDependencyResolver {
    <>
}
IMutableDependencyResolver <|.. MicrosoftDependencyResolver
class IDisposable {
    <>
}
IDisposable <|.. MicrosoftDependencyResolver
class IAsyncDisposable {
    <>
}
IAsyncDisposable <|.. MicrosoftDependencyResolver

Implements: IDependencyResolver, IReadonlyDependencyResolver, IMutableDependencyResolver, IDisposable, IAsyncDisposable

Remarks

This class enables integration with the Microsoft dependency injection container, allowing for both programmatic and externally provided service collections or providers. Once the container is built from an IServiceProvider, further modifications are not permitted. Thread safety is ensured for all registration and resolution operations. Contract-based (keyed) registrations are supported if the underlying service provider implements IKeyedServiceProvider. This resolver is suitable for scenarios requiring dynamic service registration and resolution, as well as integration with existing Microsoft.Extensions.DependencyInjection infrastructure.

Constructors

NameSummary
.ctorInitializes a new instance of the [MicrosoftDependencyResolver](# class with a new...

Properties

NameSummary
ServiceProviderGets the internal Microsoft container, or builds a new one if this instance was not initialized with one.

Methods

NameSummary
UpdateContainerUpdates this instance with a collection of configured services.
GetServiceGets an instance of the given serviceType. Must return null if the service is not available (must not throw).
GetServicesGets all instances of the given serviceType. Must return an empty collection if the service is not available (must not return null or throw).
RegisterRegisters a factory method for creating instances of the specified service type.
UnregisterCurrentUnregisters the current instance of the specified service type from the context.
UnregisterAllUnregisters all service registrations for the specified service type.
ServiceRegistrationCallbackRegisters a callback to be invoked when a service of the specified type is registered or becomes available.
HasRegistrationDetermines whether a registration exists for the specified service type.
RegisterConstantRegisters a constant value of the specified reference type for later retrieval or use.
RegisterLazySingletonRegisters a singleton service of type T that is created lazily using the specified factory function.
DisposeAsync
Dispose
Inherited members