ExtensibleInjectionEnvironment

An extensible injection environment is an injection environment that supports extensions.

While some additional features (such as factories) can be implemented purely using Tegral DI's public API, some extensions simply cannot do this and require:

  • Analysis of declarations outside of tests.

  • State storage when just putting more stuff within the environment is not feasible.

Meta-environments

Extensible environments are, at their core, environments with an additional sub-environment named the "meta environment". By default, meta-environments are EagerImmutableMetaEnvironment objects. This meta environment can be used to:

You should not implement this interface directly yourself: subclass DefaultExtensibleInjectionEnvironment instead, which already handles all the extensions-related logic.

Conventions

Extensible injection environments should follow the same conventions as regular injection environments, especially for documentation and usage. However, you must not use InjectionEnvironmentKind for extension environments -- otherwise, the DSL will not see your environment as extensible. Use ExtensibleInjectionEnvironmentKind instead.

In order to uniformly document extensibility, implementors should include the following line in their KDoc comment:

Compatible with installable extensions.

Inheritors

Properties

Link copied to clipboard

The meta environment for this environment.

Functions

Link copied to clipboard
abstract 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

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
abstract 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
abstract fun <T : Any> getResolverOrNull(identifier: Identifier<T>): IdentifierResolver<T>?

Returns the resolver associated with the given identifier.