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
Copy file name to clipboardExpand all lines: README.md
+49
Original file line number
Diff line number
Diff line change
@@ -296,6 +296,55 @@ class Shuriken implements Weapon {
296
296
}
297
297
```
298
298
299
+
### Using @provideFluent multiple times
300
+
301
+
If you try to apply `@provideFluent` multiple times:
302
+
303
+
```ts
304
+
let container =newContainer();
305
+
let provideFluent =fluentProvide(container);
306
+
307
+
const provideSingleton = (identifier:any) => {
308
+
returnprovideFluent(identifier)
309
+
.inSingletonScope()
310
+
.done();
311
+
};
312
+
313
+
function shouldThrow() {
314
+
@provideSingleton("Ninja")
315
+
@provideSingleton("SilentNinja")
316
+
classNinja {}
317
+
returnNinja;
318
+
}
319
+
```
320
+
321
+
The library will throw an exception:
322
+
323
+
> Cannot apply @provideFluent decorator multiple times but is has been used multiple times in Ninja Please use @done(true) if you are trying to declare multiple bindings!
324
+
325
+
We throw an exception to ensure that you are are not trying to apply `@fluentProvide` multiple times by mistake.
326
+
327
+
You can overcome this by passing the `force` argument to `done()`:
328
+
329
+
```ts
330
+
let container =newContainer();
331
+
let provideFluent =fluentProvide(container);
332
+
333
+
const provideSingleton = (identifier:any) => {
334
+
returnprovideFluent(identifier)
335
+
.inSingletonScope()
336
+
.done(true); // IMPORTANT!
337
+
};
338
+
339
+
function shouldThrow() {
340
+
@provideSingleton("Ninja")
341
+
@provideSingleton("SilentNinja")
342
+
classNinja {}
343
+
returnNinja;
344
+
}
345
+
```
346
+
347
+
299
348
## The auto provide utility
300
349
This library includes a small utility apply to add the default `@provide` decorator to all
0 commit comments