Skip to content
This repository has been archived by the owner on Dec 6, 2017. It is now read-only.

Commit

Permalink
chore(readme): updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj committed Apr 26, 2014
1 parent 8844211 commit b9039e8
Showing 1 changed file with 73 additions and 3 deletions.
76 changes: 73 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,77 @@
[![Build Status](https://drone.io/github.com/angular/di.dart/status.png)](https://drone.io/github.com/angular/di.dart/latest)

# A prototype of Dependency Injection framework for Dart
# Dependency Injection (DI) framework

Influenced by Pico Container, AngularJS DI, Node DI, Guice, Dagger and what not.
## Installation

Add dependency to your pubspec.yaml.

dependencies:
di: ">=0.0.39 <0.1.0"

Then, run `pub install`.

Import di.

import 'package:di/di.dart';
import 'package:di/auto_injector.dart';

## Example

```dart
import 'package:di/di.dart';
import 'package:di/auto_injector.dart';
abstract class Engine {
go();
}
class V8Engine implements Engine {
go() {
print('Vroom...');
}
}
class ElectricEngine implements Engine {
go() {
print('Hum...');
}
}
// Annotation
class Electric {
const Electric();
}
class GenericCar {
Engine engine;
GenericCar(this.engine);
drive() {
engine.go();
}
}
class ElectricCar {
Engine engine;
ElectricCar(@Electric() this.engine);
drive() {
engine.go();
}
}
void main() {
var injector = defaultInjector(modules: [new Module()
..bind(GenericCar)
..bind(ElectricCar)
..bind(Engine, toFactory: (i) => new V8Engine())

This comment has been minimized.

Copy link
@vicb

vicb Apr 26, 2014

Contributor

I like the new syntax
Do you think it would be possible to do something like bind(...).toFactory (...)

..bind(Engine, toImplementation: ElectricEngine, withAnnotation: Electric)
]);
injector.get(GenericCar).drive();
injector.get(ElectricCar).drive();
}
```

For example usage see [the tests](https://github.com/angular/di.dart/blob/master/test/main.dart).

0 comments on commit b9039e8

Please sign in to comment.