ioc_container 0.2.0
ioc_container: ^0.2.0 copied to clipboard
A Dart Ioc Container. Store and manage dependencies in one place keyed by type. It simplifies creating instances of your classes.
A Dart Ioc Container #
Code in lib/
, and example unit test in test/
.
You can do this. It's nice.
final a = A('a');
final builder = IocContainerBuilder();
builder
.addSingleton(a)
.add((i) => B(i.get<A>()))
.add((i) => C(i.get<B>()))
.add((i) => D(i.get<B>(), i.get<C>()));
final container = builder.toContainer();
var d = container.get<D>();
expect(d.c.b.a, a);
expect(d.c.b.a.name, 'a');