@flect/ioc

4.0.0 • Public • Published

flect logo

Flect/ioc

Inversion of Control Container for Flect types

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'

Package Sidebar

Install

npm i @flect/ioc

Weekly Downloads

3

Version

4.0.0

License

MIT

Unpacked Size

42.1 kB

Total Files

7

Last publish

Collaborators

  • ddurschlag