Build Status

Dice

Lightweight dependency injection framework for Dart.

Quick Guide

  1. Add the folowing to your pubspec.yaml and run pub install
    dependencies:
      dice:
        git: git://github.com/ltackmann/dice.git
  1. Create a module where you bind types to their instances
    class MyModule extends Module {
      @override
      configure() {
        // always returns the same instance
        bind(MyClass).toInstance(new MyClass());
        // invokes builder everytime type is requested
        bind(MyOtherClass).toBuilder(() => new MyOtherClass());
      }
    }
  1. Run it
    import "package:dice/dice.dart";
    main() {
      var injector = new Injector(new MyModule());
      var myClass = injector.getInstance(MyClass);
      var myOtherClass = injector.getInstance(MyOtherClass);
    }

Libraries

dice

Lightweight dependency injection framework for Dart.