Autowire is an ultra-lightweight dependency injection framework built into lambdragon.
Instead of introducing a whole new set of annotations and concepts, it relies on the type system and simple conventions.
The API for the framework is very simple:
autowire
autowire
will try to figure them out for youFor example:
class Foo {
constructor(bar: Bar){}
}
class Bar {}
// without autowire
const foo1 = new Foo(new Bar())
// with autowire
const foo = autowire(Foo)
@inject
annotationsclass Foo { constructor(bar: Bar, baz: Baz){} }
class Bar {}
class Baz { private constructor(){} }
// this will throw a compile-time error since Baz has a "private" constructor
const foo = autowire(Foo)