Context

open class Context : Named, MetaRepr, Provider, CoroutineScope

The local environment for anything being done in DataForge framework. Contexts are organized into tree structure with Global at the top. Context has properties - equivalent for system environment values, but grouped into a tree and inherited from parent context.

The main function of the Context is to provide PluginManager which stores the loaded plugins and works as a dependency injection point. The normal behaviour of the PluginManager is to search for a plugin in parent context if it is not found in a current one. It is possible to have different plugins with the same interface in different contexts in the hierarchy. The usual behaviour is to use nearest one, but it could be overridden by plugin implementation.

Types

Companion
Link copied to clipboard
common
object Companion

Functions

buildContext
Link copied to clipboard
common
fun buildContext(name: Name? = null, block: ContextBuilder.() -> Unit = {}): Context

Get and validate existing context or build and register a new child context.

close
Link copied to clipboard
common
open fun close()

Detach all plugins, and close child contexts

content
Link copied to clipboard
common
open override fun content(target: String): Map<Name, Any>

A map of direct children for specific target

fun content(target: String, inherit: Boolean): Map<Name, Any>
toMeta
Link copied to clipboard
common
open override fun toMeta(): Meta

Properties

coroutineContext
Link copied to clipboard
common
open override val coroutineContext: CoroutineContext
defaultChainTarget
Link copied to clipboard
common
open val defaultChainTarget: String

Default target for next chain segment

defaultTarget
Link copied to clipboard
common
open override val defaultTarget: String

Default target for this provider

name
Link copied to clipboard
common
override val name: Name
parent
Link copied to clipboard
common
val parent: Context?
plugins
Link copied to clipboard
common
val plugins: PluginManager

A PluginManager for current context

properties
Link copied to clipboard
common
val properties: Laminate

Context properties. Working as substitute for environment variables

Extensions

classLoaderPlugin
Link copied to clipboard
val Context.classLoaderPlugin: ClassLoaderPlugin
fetch
Link copied to clipboard
common
inline fun <T : Plugin> Context.fetch(factory: PluginFactory<T>, meta: Meta = Meta.EMPTY): T

Fetch a plugin with given meta from the context. If the plugin (with given meta) is already registered, it is returned. Otherwise, new child context with the plugin is created. In the later case the context could be retrieved from the plugin.

gather
Link copied to clipboard
common
fun <T : Any> Context.gather(target: String, type: KClass<out T>, inherit: Boolean = true): Map<Name, T>

Gather a map of all top-level objects with given target from context plugins. Content from plugins is prefixed by plugin name so name conflicts are impossible This operation could be slow in case of large number of plugins

common
inline fun <T : Any> Context.gather(target: String, inherit: Boolean = true): Map<Name, T>
inline fun <T : Any> Context.gather(inherit: Boolean = true): Map<Name, T>

All objects provided by plugins with given target and type

gatherInSequence
Link copied to clipboard
common
fun <T : Any> Context.gatherInSequence(target: String, type: KClass<out T>, inherit: Boolean = true): Sequence<Map.Entry<Name, T>>

Gather all content from context itself and its plugins in a form of sequence of name-value pairs. Ignores name conflicts.

inline fun <T : Any> Context.gatherInSequence(target: String, inherit: Boolean = true): Sequence<Map.Entry<Name, T>>
logger
Link copied to clipboard
common
val Context.logger: LogManager

Context log manager inherited from parent

modify
Link copied to clipboard
common
fun Context.modify(block: ContextBuilder.() -> Unit): Context

Check if current context contains all plugins required by the builder and return it does or forks to a new context if it does not.

resolve
Link copied to clipboard
common
fun <T : Any> Context.resolve(target: String, name: Name, type: KClass<out T>): T?
inline fun <T : Any> Context.resolve(target: String, name: Name): T?

Resolve a top level object with given target and name in a Context own scope or its plugins.

services
Link copied to clipboard
inline fun <T : Any> Context.services(): Sequence<T>