DIContext
classin packageklyn.di
public class DIContext
DIContext

Dependency injection context.

This context stores named components, discovers annotated components and resolves dependencies by name or assignable type.

import klyn.di

context = DIContext()
service = Object()
context.registerComponent("service", service)
assert context.getComponent("service") == service
Constructors
Modifier and Type Member Description
public DIContext Creates an empty dependency injection context.
public DIContext
DIContext(packages as IList<String>)
Creates a dependency injection context restricted to selected packages.
Methods
Modifier and Type Member Description
public close
close() as Void throws Exception
Closes this context and destroys managed components in reverse creation order.
public createComponent
createComponent(typeInfo as Type, name as String = "") as Object throws Exception
Creates and manages a component from reflected type metadata.
public destroyComponent
destroyComponent(name as String) as Boolean throws Exception
Destroys and unregisters one component.
public getComponent
getComponent(name as String) as Object
Returns a registered component by name.
public registerComponent
registerComponent(name as String, component as Object) as Void
Registers a component instance under a name.
public scanAnnotations
scanAnnotations() as Void throws Exception
Scans annotations and registers discovered singleton components.