@@ -291,7 +291,9 @@ class UserController {
291291}
292292
293293var inj = new Injector([UserList, UserController]);
294- var ctrl:UserController = inj.get(UserController); //ctr.ul instanceof Promise;
294+ var ctrl:UserController = inj.get(UserController);
295+ // UserController responsible for dealing with asynchrony.
296+ expect(ctrl.ul).toBePromise();
295297```
296298
297299#### Async Binding + Sync Dependency:
@@ -308,7 +310,14 @@ var inj = new Injector([
308310 bind(UserList).toAsyncFactory(() => fetchUsersUsingHttp().then((u) => new UserList(u))),
309311 UserController
310312]);
311- var ctrl:Promise = inj.asyncGet(UserController); //ctr.ul instanceof UserList;
313+ var ctrlPromise:Promise = inj.asyncGet(UserController);
314+ // Caller opts in to dealing with asynchrony.
315+ ctrlPromise.then((ctrl) {
316+ expect(ctrl).toBeAnInstanceOf(UserController);
317+ expect(ctrl.ul).toBeAnInstanceOf(UserList);
318+ });
319+ // No synchronous provider for UserList, results in a NoProviderError.
320+ expect(() => inj.get(UserController)).toThrow(new NoProviderError(...));
312321```
313322
314323
@@ -326,7 +335,15 @@ var inj = new Injector([
326335 bind(UserList).toAsyncFactory(() => fetchUsersUsingHttp().then((u) => new UserList(u))),
327336 UserController
328337]);
329- var ctrl = inj.get(UserController); //ctr.ul instanceof UserList;
338+ var ctrl = inj.get(UserController);
339+ // UserController responsible for dealing with asynchrony.
340+ expect(ctrl.ul).toBePromise();
341+
342+ var ctrlPromise = inj.asyncGet(UserController);
343+ ctrlPromise.then((ctrl) {
344+ // UserList still provided async.
345+ expect(ctrl.ul).toBePromise();
346+ });
330347```
331348
332349
@@ -363,7 +380,10 @@ var inj = new Injector([
363380 bind('MyClassFactory').toFactory(dep => () => new MyClass(dep), [SomeDependency])
364381]);
365382
366- var inj.get('MyClassFactory')();
383+ var factory = inj.get('MyClassFactory');
384+ var instance1 = factory(), instance2 = factory();
385+ // Depends on the implementation of MyClass, but generally holds.
386+ expect(instance1).not.toBe(instance2);
367387```
368388
369389
@@ -390,4 +410,4 @@ var inj = new Injector([
390410var engine = inj.get(ENGINE_KEY); // no mapping
391411```
392412
393- Every key has an id, which we utilize to store bindings and instances. Essentially, ` inj.get(ENGINE_KEY) ` is an array read, which is very fast.
413+ Every key has an id, which we utilize to store bindings and instances. Essentially, ` inj.get(ENGINE_KEY) ` is an array read, which is very fast.
0 commit comments