@flect/ioc
v4.0.0
Published
Inversion of control container for flect
Downloads
33
Maintainers
Readme
Introduction
Flect/ioc is a library for building and resolving a dependency graph.
Usage
const Animal = record({
legCount: numberType,
sound: stringType
});
type Animal = Reify<typeof Animal>;
const Person = record({
pet: record({
legCount: numberType,
sound: stringType
})
});
type Person = Reify<typeof Person>;
class Cat implements Animal {
get legCount() {
return 4;
}
get sound() {
return "meow";
}
}
const c = new Container();
c.bind(Person)
.with(Animal)
.toFactory((a: Animal) => ({pet: a}));
c.bind(Animal).toFactory(() => new Cat());
console.log(c.resolve(Person).pet.sound); // Goes 'woof'