Skip to content

InstanceGenericFirstDependencyResolver class

Defined in

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

Summary

View source

Generic-first implementation of IDependencyResolver optimized for AOT compilation, with per-resolver instance isolation using resolver-local state.

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 InstanceGenericFirstDependencyResolver
class IDependencyResolver {
    <>
}
IDependencyResolver <|.. InstanceGenericFirstDependencyResolver
class IReadonlyDependencyResolver {
    <>
}
IReadonlyDependencyResolver <|.. InstanceGenericFirstDependencyResolver
class IMutableDependencyResolver {
    <>
}
IMutableDependencyResolver <|.. InstanceGenericFirstDependencyResolver
class IDisposable {
    <>
}
IDisposable <|.. InstanceGenericFirstDependencyResolver

Implements: IDependencyResolver, IReadonlyDependencyResolver, IMutableDependencyResolver, IDisposable

Remarks

This resolver favors the generic API surface (GetService, GetServices) for performance, while still supporting non-generic APIs (GetService, GetServices) through an internal type registry.

Registration semantics:

  • GetService returns the most recently registered service for the type (last registration wins).
  • GetServices returns all registrations (order is implementation-defined by the underlying containers/registry).
  • Contracts provide named variants of the same service type.

Disposal semantics:

  • Constants and lazy singletons that implement IDisposable are disposed when the resolver is disposed.
  • Exceptions thrown from callbacks or disposal actions are suppressed during Dispose.

Thread-safety:

  • Registration-change callbacks and disposal action bookkeeping are thread-safe.
  • Resolve operations avoid additional locking within this type; underlying containers/registry are expected to be concurrency-safe for their usage patterns.

Constructors

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

Methods

NameSummary
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