MixedImmutableEnvironment

class MixedImmutableEnvironment(context: ExtensibleEnvironmentContext, metaEnvironmentKind: InjectionEnvironmentKind<*> = EagerImmutableMetaEnvironment) : DefaultExtensibleInjectionEnvironment

An injection environment implementation with a mixed evaluation strategy.

Mixed evaluation strategy here means that:

  • Components are created eagerly, i.e. when this environment is created

  • Injections are performed lazily within the same component, e.g. a component A that wants to have B injected will only actually get B when A performs a get on B.

Mixed evaluation allows for lock-free thread safety for component creation and occasional locking thread safety on injections.

Due to injections being made lazily, this environment supports cyclic dependencies (class A requires B, class B requires A) and self-injections (class C requires itself).

Characteristics

  • Eager object creation. Objects are created upon construction of this environment.

  • Lazy object injection. Objects are injected upon first use, and are only computed once.

  • Idempotent/Immutable. Objects cannot be replaced, injection methods will always return the same thing.

Compatible with installable extensions.

Constructors

Link copied to clipboard
constructor(context: ExtensibleEnvironmentContext, metaEnvironmentKind: InjectionEnvironmentKind<*> = EagerImmutableMetaEnvironment)

Functions

Link copied to clipboard
open override fun <T : Any> createInjector(identifier: Identifier<T>, onInjection: (T) -> Unit): Injector<T>

Creates an Injector that can be used as a property delegator, bound against the given identifier.

Link copied to clipboard

Performs the internal logic required for setting up a meta-environment. When creating extensible environments, you should either call this function to create your meta environment, or subclass DefaultExtensibleInjectionEnvironment which will do it for you.

Link copied to clipboard
open fun <T : Any> get(identifier: Identifier<T>): T

Gets the component identified by the given identifier. No guarantees are given on this function - it may not be idempotent, depending on the actual implementation.

Link copied to clipboard
inline fun <T : Any> InjectionEnvironment.get(qualifier: Qualifier = EmptyQualifier): T

Gets the component identified by the given type turned into an Identifier with an optional qualifier. Throws an exception if no component with this identifier exists.

Link copied to clipboard
open override fun getAllIdentifiers(): Sequence<Identifier<*>>

Returns a sequence of all the known identifiers present in this environment.

Link copied to clipboard

Retrieve the fundef wrapper for the given function, or throw an exception if no such fundef could be found.

Link copied to clipboard
open override fun <T : Any> getOrNull(identifier: Identifier<T>): T?

Gets the component identified by the given identifier, or null if no such component exists. No guarantees are given on this function - it may not be idempotent, depending on the actual implementation.

Link copied to clipboard
inline fun <T : Any> InjectionEnvironment.getOrNull(qualifier: Qualifier = EmptyQualifier): T?

Gets the component identified by the given type turned into an Identifier with an optional qualifier. Returns null if no component with this identifier exists.

Link copied to clipboard
open override fun <T : Any> getResolverOrNull(identifier: Identifier<T>): IdentifierResolver<T>?

Returns the resolver associated with the given identifier.

Properties

Link copied to clipboard

The meta environment for this environment.