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>());
Annotations
  • @Target({TargetKind.parameter})

Constructors

Inject(Object token)
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
token Object
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited