dado 0.5.1 copy "dado: ^0.5.1" to clipboard
dado: ^0.5.1 copied to clipboard

Dart 1 only

An experimental dependency injection container for Dart

Dado #

Dado is a dependency injection framework for Dart.

Dado attempts to have minimal set of features and a syntax that takes advantage of Dart, which makes it different from many other popular DI frameworks.

Dado tries to make DI more lightweight by letting you define modules as Dart classes and as declaratively as possible. Bindings can be define by simply declaring an abstract method:

class MyModule extends Module {
  Foo get foo;
}

See the tests for more examples.

Principles #

  1. Idiomatic: Dart is a different language than JavaScript or Java and has different capabilities and styles. Part of Dado's approach is driven by a desire to figure out exactly what a Dart DI framework should look like. We try to use language features to drive configuration whenever possible.
  2. Dev-Time Productivity, Deploy-Time Optimization Dado uses Dart mirrors to implement injectors dynamically, but we are working on a code generator that will allow tools like dart2js to produce smaller output.
  3. Play Well with the Web: Dart is at home on the web and Dado should be too, working well with the DOM, and new technologies like custom elements and MDV.
  4. Simplicity Dado should be as simple as possible, but no simpler.
  5. Toolability Dado should work well tools and operations like static find references, refactoring, minifiers, tree-shakers, etc.

Documentation #

Dartdoc documentation for Dado can be found here: http://dart-lang.github.io/dado/docs/dado.html

Example #

import 'package:dado/dado.dart';

class MyModule extends Module {

  // binding to an instance, similar to bind().toInstance() in Guice
  String serverAddress = "127.0.0.1";

  // Getters define a singleton, similar to bind().to().in(Singleton.class)
  // in Guice
  Foo get foo;

  // Methods define a factory binding, similar to bind().to() in Guice
  Bar newBar();

  // Methods that delegate to bindTo() bind a type to a specific
  // implementation of that type
  Baz get baz => bindTo(Baz).singleton;

  // Bindings can be made to provider methods
  Qux newQux() => bindTo(Qux)
      .providedBy((Foo foo) => new Qux(foo, 'not injected')).newInstance();
}

class Bar {
  // A default method is automatically injected with dependencies
  Bar(Foo foo);
}

main() {
  var injector = new Injector([MyModule]);
  Bar bar = injector.getInstance(Bar);
}

Status #

Dado is under active development. It has a few tests, but has not been used in production yet.

Known Issues and Limitations #

  • Injectable classes must either have a default constructor or a single constructor.
  • There can only be one binding per type, because parameter annotations cannot be access via mirrors yet. When issue 11418 is fixed, Dado will respect annotations of parameters.
  • Functions cannot be injected yet.
  • Named parameters are not supported.
  • No custom scope support. The only scopes are unscoped and singleton. Hierarchical modules might be enough.
  • Modules must extend Module. When mixins are better supported in Dart, Module can be mixed in instead.

Star Fishing #

These are open issues that are blocking certain features od Dado:

0
likes
10
pub points
0%
popularity

Publisher

unverified uploader

An experimental dependency injection container for Dart

Homepage

Documentation

Documentation

License

BSD-3-Clause (LICENSE)

Dependencies

logging

More

Packages that depend on dado