Skip to content

ModernDependencyResolver class

Defined in

Namespace: Splat Assembly: Splat.Core.dll Full name: Splat.ModernDependencyResolver Modifiers: public

Summary

View source

This class is a dependency resolver written for modern C# 5.0 times. It implements all registrations via a Factory method. With the power of Closures, you can actually implement most lifetime styles (i.e. construct per call, lazy construct, singleton) using this.

Unless you have a very compelling reason not to, this is the only class you need in order to do dependency resolution, don't bother with using a full IoC container.

Applies to

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

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

Implements: IDependencyResolver, IReadonlyDependencyResolver, IMutableDependencyResolver, IDisposable

Constructors

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

Methods

NameSummary
HasRegistrationDetermines whether a registration exists for the specified service type.
RegisterRegisters a factory method for creating instances of the specified service type.
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).
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.
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.
DuplicateGenerates a duplicate of the resolver with all the current registrations. Useful if you want to generate temporary resolver using the...
Dispose
Inherited members