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
Resolve is like `container.get<T>(serviceIdentifier: ServiceIdentifier<T>)` but it allows users to create an instance wven if no bindings have been declared:
285
+
286
+
```ts
287
+
@injectable()
288
+
classKatana {
289
+
public hit() {
290
+
return"cut!";
291
+
}
292
+
}
293
+
294
+
@injectable()
295
+
classNinjaimplementsNinja {
296
+
public katana:Katana;
297
+
publicconstructor(katana:Katana) {
298
+
this.katana=katana;
299
+
}
300
+
public fight() { returnthis.katana.hit(); }
301
+
}
302
+
303
+
const container =newContainer();
304
+
container.bind(Katana).toSelf();
305
+
306
+
const tryGet = () =>container.get(Ninja);
307
+
expect(tryGet).to.throw("No matching bindings found for serviceIdentifier: Ninja");
308
+
309
+
const ninja =container.resolve(Ninja);
310
+
expect(ninja.fight()).to.eql("cut!");
311
+
```
312
+
313
+
Please note that it only allows to skip declaring a binding for the root element in the dependency graph (composition root). All the sub-dependencies (e.g. `Katana` in the preceding example) will require a binding to be declared.
0 commit comments