Vernal
Vernal IoC container for TypeScript
Spring Boot inspired IoC container for TypeScript originally created for Node.js applications.
The library provides @Component(type)/@Singleton/@Prototype
, @Autowire(class|name)/@Inject(class|name)
and @PostConstruct
decorators.
-
@Component(type)
- registers the annotated class as a bean using typetype
. Note that it is also possible to useVernal.registerBean
instead of the @Component decorator. -
@Singleton
- shorthand for @Component(BeanType.SINGLETON). -
@Prototype
- shorthand for @Component(BeanType.PROTOTYPE). -
@Autowire(class|name)/@Inject(class|name)
- initializes a class field to the registered bean value. Bean can be specified by class or by name -
@PostConstruct
- designates a sync or async method to run after the bean is completely initialized
In special cases it is also possible to use Vernal.registerValue
to register free-form values or Vernal.registerInstance
to register existing object instances.
To retrieve a bean instance outside of injection context use Vernal.getBeanInstance(class|name)
.
Usage example
; process.on'unhandledRejection',; Vernal.registerInstancenew X; Vernal.registerValue'V', ; ;