ModernDependencyResolver class¶
Defined in
Namespace: Splat
Assembly: Splat.Core.dll
Full name: Splat.ModernDependencyResolver
Modifiers: public
Summary¶
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¶
| Name | Summary |
|---|---|
| .ctor | Initializes a new instance of the [ModernDependencyResolver](# class. |
Methods¶
| Name | Summary |
|---|---|
| HasRegistration | Determines whether a registration exists for the specified service type. |
| Register | Registers a factory method for creating instances of the specified service type. |
| GetService | Gets an instance of the given serviceType. Must return null if the service is not available (must not throw). |
| GetServices | Gets all instances of the given serviceType. Must return an empty collection if the service is not available (must not return null or throw). |
| UnregisterCurrent | Unregisters the current instance of the specified service type from the context. |
| UnregisterAll | Unregisters all service registrations for the specified service type. |
| ServiceRegistrationCallback | Registers a callback to be invoked when a service of the specified type is registered or becomes available. |
| RegisterConstant | Registers a constant value of the specified reference type for later retrieval or use. |
| RegisterLazySingleton | Registers a singleton service of type T that is created lazily using the specified factory function. |
| Duplicate | Generates a duplicate of the resolver with all the current registrations. Useful if you want to generate temporary resolver using the... |
| Dispose |