- the 4.x
guid(): string
method has been replaced byid(): number
- the property
guid: string
has been replaced byid: number
in the following interfaces and their implementations thub.com/inversify/InversifyJS/blob/master/src/contain* Binding
-
The 2.x
Kernel
is namedContainer
in 3.x -
The 2.x
Kernel
methodgetServiceIdentifierAsString
is not a method ofContainer
in 3.x. -
The 2.x
PlanAndResolveArgs
interface is namedNextArgs
in 3.0 and some of its properties have changed. -
The
Provider
signature has been modified. -
In 3.x,
strictNullChecks
is enabled. -
The resolution logic in 2.0 and 3.0 is slightly different in order to support new features like optional dependencies and defaults contextual injections.
Version 2.x introduces some changes in the API.
The 1.x TypeBinding
is named Binding
in 2.x
The 1.x BindingScopeEnum
is named BindingScope
in 2.x
The 1.x binding syntax looks as follows:
container.bind(new TypeBinding<FooInterface>("FooInterface", Foo, BindingScopeEnum.Transient));
The 2.x binding syntax looks as follows:
container.bind<FooInterface>("FooInterface").to(Foo).inTransientScope()
The 1.x container.resolve<T>(identifier: string)
method is now container.get<T>(identifier: string)
2.x.
The 1.x resolution syntax looks as follows:
var foobar = container.resolve<FooBarInterface>("FooBarInterface");
The 2.x resolution syntax looks as follows:
var foobar = container.get<FooBarInterface>("FooBarInterface");
All your classes must be decorated with the @injectable()
decorator. If your class has a dependency in a class that's enough:
@injectable()
class Katana {
public hit() {
return "cut!";
}
}
@injectable()
class Shuriken {
public throw() {
return "hit!";
}
}
@injectable()
class Ninja implements Ninja {
private _katana: Katana;
private _shuriken: Shuriken;
constructor(
katana: Katana,
shuriken: Shuriken
) {
this._katana = katana;
this._shuriken = shuriken;
}
public fight() { return this._katana.hit(); };
public sneak() { return this._shuriken.throw(); };
}
But if your class has a dependency on an interface you will also need to use the @inject
decorator.
@injectable()
class Ninja implements Ninja {
private _katana: Katana;
private _shuriken: Shuriken;
constructor(
@inject("Katana") katana: Katana,
@inject("Shuriken") shuriken: Shuriken
) {
this._katana = katana;
this._shuriken = shuriken;
}
public fight() { return this._katana.hit(); };
public sneak() { return this._shuriken.throw(); };
}