You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This small utility allows you to declare bindings using decorators:
@@ -67,14 +68,14 @@ var kernel = new Kernel();
67
68
let provide =makeProvideDecorator(kernel);
68
69
69
70
@provide(Katana)
70
-
classKatanaimplementsIKatana {
71
+
classKatanaimplementsWeapon {
71
72
public hit() {
72
73
return"cut!";
73
74
}
74
75
}
75
76
76
77
@provide(Shuriken)
77
-
classShurikenimplementsIShuriken {
78
+
classShurikenimplementsThrowableWeapon {
78
79
public throw() {
79
80
return"hit!";
80
81
}
@@ -99,9 +100,9 @@ class Katana {
99
100
100
101
@provide(Ninja)
101
102
classNinja {
102
-
private _katana:Katana;
103
+
private _katana:Weapon;
103
104
publicconstructor(
104
-
katana:Katana
105
+
katana:Weapon
105
106
) {
106
107
this._katana=katana;
107
108
}
@@ -120,24 +121,24 @@ These bindings use classes as identidiers but you can also use string literals a
120
121
121
122
```ts
122
123
let TYPE = {
123
-
IKatana: "IKatana",
124
-
INinja: "INinja"
124
+
IKatana: "Katana",
125
+
INinja: "Ninja"
125
126
};
126
127
127
-
@provide(TYPE.IKatana)
128
-
classKatanaimplementsIKatana {
128
+
@provide(TYPE.Katana)
129
+
classKatanaimplementsWeapon {
129
130
public hit() {
130
131
return"cut!";
131
132
}
132
133
}
133
134
134
-
@provide(TYPE.INinja)
135
-
classNinjaimplementsINinja {
135
+
@provide(TYPE.Ninja)
136
+
classNinjaimplementsNinja {
136
137
137
-
private _katana:IKatana;
138
+
private _katana:Weapon;
138
139
139
140
publicconstructor(
140
-
@inject(TYPE.IKatana) katana:IKatana
141
+
@inject(TYPE.Katana) katana:Weapon
141
142
) {
142
143
this._katana=katana;
143
144
}
@@ -151,24 +152,24 @@ You can also use symbols as identifiers:
151
152
152
153
```ts
153
154
let TYPE = {
154
-
IKatana: Symbol("IKatana"),
155
-
INinja: Symbol("INinja")
155
+
Katana: Symbol("Katana"),
156
+
Ninja: Symbol("Ninja")
156
157
};
157
158
158
-
@provide(TYPE.IKatana)
159
-
classKatanaimplementsIKatana {
159
+
@provide(TYPE.Katana)
160
+
classKatanaimplementsWeapon {
160
161
public hit() {
161
162
return"cut!";
162
163
}
163
164
}
164
165
165
-
@provide(TYPE.INinja)
166
-
classNinjaimplementsINinja {
166
+
@provide(TYPE.Ninja)
167
+
classNinjaimplementsNinja {
167
168
168
-
private _katana:IKatana;
169
+
private _katana:Weapon;
169
170
170
171
publicconstructor(
171
-
@inject(TYPE.IKatana) katana:IKatana
172
+
@inject(TYPE.Katana) katana:Weapon
172
173
) {
173
174
this._katana=katana;
174
175
}
@@ -179,9 +180,13 @@ class Ninja implements INinja {
179
180
```
180
181
181
182
### Fluent binding decorator
182
-
The basic `@provide` decorator doesn't allow you to declare contextual constraints, scope and other advanced binding features. However, `inversify-binding-decorators` includes a second decorator that allows you to achieve access the full potential of the fluent binding syntax:
183
+
The basic `@provide` decorator doesn't allow you to declare contextual constraints,
184
+
scope and other advanced binding features. However, `inversify-binding-decorators`
185
+
includes a second decorator that allows you to achieve access the full potential
186
+
of the fluent binding syntax:
183
187
184
-
The decorator returned by `makeProvideDecorator` is not fluent and is very limited when compared to `makeFluentProvideDecorator`:
188
+
The decorator returned by `makeProvideDecorator` is not fluent and is very limited
The contents of the entities.ts file are the following:
294
+
288
295
```ts
289
296
export { defaultasWarrior } from"./warrior";
290
297
export { defaultasKatana } from"./katana";
291
298
```
299
+
292
300
The contents of the katana.ts file are the following:
301
+
293
302
```ts
294
303
classKatana {
295
304
public use() {
@@ -299,19 +308,21 @@ class Katana {
299
308
300
309
exportdefaultKatana;
301
310
```
311
+
302
312
The contents of the warrior.ts file are the following:
313
+
303
314
```ts
304
315
importKatanafrom"./katana";
305
316
import { inject } from"inversify";
306
317
307
318
classWarrior {
308
-
private _weapon:Katana;
319
+
private _weapon:Weapon;
309
320
publicconstructor(
310
321
// we need to declare binding because auto-provide uses
311
322
// @injectbale decorator at runtime not compilation time
312
323
// in the future maybe this limitation will desapear
313
324
// thanks to design-time decorators or some other TS feature
314
-
@inject(Katana) weapon:Katana
325
+
@inject(Katana) weapon:Weapon
315
326
) {
316
327
this._weapon=weapon;
317
328
}
@@ -355,6 +366,11 @@ following conditions:
355
366
The above copyright notice and this permission notice shall be included in all copies or substantial
356
367
portions of the Software.
357
368
358
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
369
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
370
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
371
+
PURPOSE AND NONINFRINGEMENT.
359
372
360
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
373
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
374
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
375
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0 commit comments