Skip to content
IoC container with Dagger like abstractions (dependency injection with Components, SubComponents, Modules), supports components collaboration, singletons, tagging.
Dart Ruby Other
Branch: master
Clone or download
Latest commit 3f7319f Feb 16, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
documentation/images Initial commit. Dec 2, 2019
example-readme Version 1.0.5. Feb 12, 2020
example Dependencies update. Feb 16, 2020
lib Version 1.0.5. Feb 12, 2020
test Tests update. Dec 3, 2019
.gitignore Version 1.0.5. Feb 12, 2020
.metadata ... Nov 30, 2019
CHANGELOG.md Version 1.0.5. Feb 12, 2020
LICENSE Version 1.0.0. Dec 2, 2019
README.md Version 1.0.5. Feb 12, 2020
napomene.txt Version 1.0.5. Feb 12, 2020
pubspec.lock Version 1.0.5. Feb 12, 2020
pubspec.yaml Version 1.0.5. Feb 12, 2020

README.md

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);
  }
}

Configuration

Ignore assertion errors for unregistered types

// Globally  
Daggerito.configure(silent: true);

// or
// Component specific
  AppComponent._({
    @required SharedPreferences sharedPreferences,
  }) : super(
          modules: [
            CommonModule(sharedPreferences),
            PublicModule(),
          ],
          silent: true,
        )
You can’t perform that action at this time.