Commit 478e56b
committed
fix: handle correctly non-shared instances in injector
Currently `$injector` can have non-shared instances by setting the third argument of the `register` method to false, i.e.:
```
$injector.register("myClass", MyClass, false);
```
However, in this case, the injector caches only the last created instance and this way it will not call the dispose method of all created instances. Fix this by caching all instances in an array and iterrate over them when disposing them.
This way we can have correct resolving of instances by name when constructor has non-injectable dependencies:
```
class A {
constructor(private stringArg: string) { }
}
$injector.register("a", A, false);
// in another file:
$injector.resolve("a", { stringArg: "stringValue" }); //returns new instance;
$injector.resolve("a", { stringArg: "different stringValue" }); //returns new instance;
```1 parent 545b3a5 commit 478e56b
2 files changed
+47
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
230 | 254 | | |
231 | 255 | | |
232 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
286 | 291 | | |
287 | 292 | | |
288 | 293 | | |
| |||
370 | 375 | | |
371 | 376 | | |
372 | 377 | | |
| 378 | + | |
373 | 379 | | |
374 | 380 | | |
375 | 381 | | |
376 | 382 | | |
377 | 383 | | |
378 | 384 | | |
379 | 385 | | |
380 | | - | |
| 386 | + | |
381 | 387 | | |
382 | 388 | | |
383 | 389 | | |
384 | 390 | | |
385 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
386 | 397 | | |
387 | 398 | | |
388 | 399 | | |
389 | 400 | | |
390 | 401 | | |
391 | 402 | | |
392 | | - | |
| 403 | + | |
393 | 404 | | |
394 | 405 | | |
395 | 406 | | |
| |||
424 | 435 | | |
425 | 436 | | |
426 | 437 | | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
431 | 444 | | |
432 | 445 | | |
433 | 446 | | |
| |||
0 commit comments