Daggerito

pub

IoC container with Dagger like abstractions (dependency injection with Components, SubComponents, Modules), supports components collaboration, singletons, tagging.

Example

Example
Basic container test
Components collaboration test
Daggerito in usage (Routex app)

Code sample

import 'example/components.dart';
import 'example/models.dart';
import 'example/modules.dart';

void main() {
  test('Components collaboration test', () {
    var aComponent = AComponent([AModule(), BModule(), CModule()]);
    var bComponent = BSubComponent(aComponent, [DModule(), EModule()]);
    var cComponent = CComponent([FModule(), GModule()]);
    var dComponent =
        DSubComponent([bComponent, cComponent], [HModule(), IModule()]);

    //Component is dart callable class, same as component.container.resolve()
    H1 model = dComponent();
    expect(model != null, isTrue);
  });
}
class HModule implements Module {
  @override
  void register(DependencyContainer container) {
    container.register(($) => H1($(), $(), $(), $("t1"), $("t2"), $(), $()));
    container.register(($) => H2());
  }
}

class DSubComponent extends SubComponent {
  DSubComponent(
    List<Component> components,
    List<Module> modules,
  ) : super(components, modules: modules);
}

class H1 {
  H1(A2 model1, B1 model2, D1 model3, F1 model4, F1 model5, H2 model6,
      I2 model7) {
    assert(model1 != null);
    assert(model2 != null);
    assert(model3 != null);
    assert(model4 != null);
    assert(model5 != null);
    assert(model6 != null);
    assert(model7 != null);
    assert(model4.description != model5.description);
  }
}

Libraries

daggerito