GithubHelp home page GithubHelp logo

stantronic / daggerito Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sidinaz/daggerito

0.0 0.0 0.0 737 KB

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

License: BSD 2-Clause "Simplified" License

Dart 97.04% Kotlin 0.28% Ruby 2.37% Swift 0.28% Objective-C 0.03%

daggerito's Introduction

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 = Component(modules: [AModule(), BModule(), CModule()]);
    var bComponent = SubComponent(aComponent, modules: [DModule(), EModule()]);
    var cComponent = SubComponent(bComponent, modules: [FModule(), GModule()]);
    var dComponent = SubComponent(cComponent, modules: [HModule(), IModule()]);

    //Component is dart callable class, same as component.container.resolve()
    var hasModel = dComponent.container.has<H1>();
    expect(hasModel, isTrue);
    expect(aComponent.container.has<F1>("t1"), isFalse);
    expect(bComponent.container.has<F1>("t1"), isFalse);
    expect(cComponent.container.has<F1>("t1"), isTrue);
    expect(dComponent.container.has<F1>("t1"), isTrue);
    print(dComponent.container.definitions);
  });
}
class HModule implements Module {
  @override
  void register(DependencyContainer container) {
    container.register(($) => H1($(), $(), $(), $("t1"), $("t2"), $(), $()));
    container.register(($) => H2());
  }
}

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,
        )

Tips

// When silent mode is off (default) use has to check for type availability.  
if(container.has<H1>())...

// Register as defined type
container.register((_) => SystemClock(), as: Clock);

daggerito's People

Contributors

sidinaz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.