klyn.di.DIContext.createComponent
method
public createComponent(typeInfo as Type, name as String = "") as Object throws Exception:
Description

Creates and manages a component from reflected type metadata.

The context invokes the zero-argument constructor, registers the resulting instance, injects properties annotated with @Autowired, then invokes zero-argument methods annotated with @InitMethod.

Parameters
ParameterDescription
typeInfoConcrete component type.
nameOptional registration name. The short type name is used when omitted.
Returns

The created and initialized component.

Throws
  • ValueException if the type is missing, abstract or an interface.
  • IllegalStateException if the registration name is already used.
  • Exception if construction, injection or initialization fails.
Example
import klyn.di

context = DIContext()
service = context.createComponent(MyService.type, "service") as MyService
assert context.getComponent("service") is service