Skip to content

GlobalGenericFirstDependencyResolver class

Defined in

Namespace: Splat Assembly: Splat.Core.dll Full name: Splat.GlobalGenericFirstDependencyResolver Modifiers: public sealed

Summary

View source

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:

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

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

Methods

NameSummary
static ClearClears all global registrations and tracked container instances for the entire process.
GetServiceGets an instance of the given T. Must return null if the service is not available (must not throw).
GetServicesGets all instances of the given T. Must return an empty collection if the service is not available (must not return null or throw).
HasRegistrationDetermines whether a registration exists for the specified service type.
RegisterRegister 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...
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.
UnregisterCurrentUnregisters the current instance of the specified type from the context.
UnregisterAllUnregisters all instances of the specified type from the registry or container.
ServiceRegistrationCallbackRegisters 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
Inherited members