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})
Properties
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