dice 1.0.4 dice: ^1.0.4 copied to clipboard
Lightweight dependency injection framework for Dart.
Dice #
Lightweight dependency injection framework for Dart.
Quick Guide #
- Add the folowing to your pubspec.yaml and run pub install
dependencies:
dice: any
- 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());
}
}
- Run it
import "package:dice/dice.dart";
main() {
var injector = new Injector(new MyModule());
var myClass = injector.getInstance(MyClass);
var myOtherClass = injector.getInstance(MyOtherClass);
}