GlobalGenericFirstDependencyResolver class¶
Defined in
Namespace: Splat
Assembly: Splat.Core.dll
Full name: Splat.GlobalGenericFirstDependencyResolver
Modifiers: public sealed
Summary¶
Global, generic-first implementation of IDependencyResolver optimized for AOT compilation.
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 GlobalGenericFirstDependencyResolver
class IDependencyResolver {
<>
}
IDependencyResolver <|.. GlobalGenericFirstDependencyResolver
class IReadonlyDependencyResolver {
<>
}
IReadonlyDependencyResolver <|.. GlobalGenericFirstDependencyResolver
class IMutableDependencyResolver {
<>
}
IMutableDependencyResolver <|.. GlobalGenericFirstDependencyResolver
class IDisposable {
<>
}
IDisposable <|.. GlobalGenericFirstDependencyResolver
Implements: IDependencyResolver, IReadonlyDependencyResolver, IMutableDependencyResolver, IDisposable
Remarks¶
This resolver uses static generic containers for type-safe, reflection-free service resolution:
- GetService and GetServices are the preferred fast paths.
- Non-generic APIs (GetService / GetServices) are supported via an internal type registry.
- Contracts allow named variants of the same service type.
Registration semantics:
- GetService returns the most recently registered instance for service type (last registration wins).
- GetServices returns all registrations for registrations of that type.
Thread-safety:
- Resolution is lock-free within this type (uses published snapshots and static container concurrency).
- Callback and disposal bookkeeping is thread-safe (protected by internal gates).
Disposal:
- Constants and lazy singletons that implement IDisposable are disposed when this resolver instance is disposed.
- Callback and disposal exceptions are suppressed during Dispose.
Clear clears global registrations and static containers for the entire process.
Constructors¶
| Name | Summary |
|---|---|
| .ctor | Initializes a new instance of the [GlobalGenericFirstDependencyResolver](# class. |
Methods¶
| Name | Summary |
|---|---|
| static Clear | Clears all global registrations and tracked container instances for the entire process. |
| GetService | Gets an instance of the given T. Must return null if the service is not available (must not throw). |
| GetServices | Gets all instances of the given T. Must return an empty collection if the service is not available (must not return null or throw). |
| HasRegistration | Determines whether a registration exists for the specified service type. |
| Register | Register a function with the resolver which will generate an object for the specified service type. Most implementations will use a stack based approach to allow for... |
| 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. |
| UnregisterCurrent | Unregisters the current instance of the specified type from the context. |
| UnregisterAll | Unregisters all instances of the specified type from the registry or container. |
| ServiceRegistrationCallback | Registers a callback to be invoked when a service of type T is registered, and returns a disposable object that can be used to unregister the callback. |
| Dispose |