Inject class

A parameter metadata that specifies a dependency.

Example

class Engine {}

@Injectable()
class Car {
  final Engine engine;
  Car(@Inject("MyEngine") this.engine);
}

var engine = new Engine();

var injector = Injector.resolveAndCreate([
 new Provider("MyEngine", useValue: engine),
 Car
]);

expect(injector.get(Car).engine, same(engine));

When @Inject() is not present, Injector will use the type annotation of the parameter.

Example

class Engine {}

@Injectable()
class Car {
  Car(Engine engine) {} //same as Car(@Inject(Engine) Engine engine)
}

var injector = Injector.resolveAndCreate([Engine, Car]);
expect(injector.get(Car).engine, new isInstanceOf<Engine>());

Constructors

Inject(dynamic token)
const

Properties

token → dynamic
final
hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

toString() → String
Returns a string representation of this object.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited