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>());
Static Methods
-
tokenToString(
token) → String
Constructors
- Inject(token)
-
const
Properties
- hashCode → int
-
Get a hash code for this object.
read-only, inherited - runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited - token → dynamic
-
read-only
Operators
-
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
toString(
) → String -
Returns a string representation of this object.