4.0.0 • Published 2 years ago

@flect/ioc v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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'