|
6 | 6 | CONST_EXPR, |
7 | 7 | stringify, |
8 | 8 | isArray, |
| 9 | + isType, |
| 10 | + isFunction, |
9 | 11 | normalizeBool |
10 | 12 | } from 'angular2/src/core/facade/lang'; |
11 | 13 | import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions'; |
@@ -344,7 +346,13 @@ export class BindingBuilder { |
344 | 346 | * expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true); |
345 | 347 | * ``` |
346 | 348 | */ |
347 | | - toClass(type: Type): Binding { return new Binding(this.token, {toClass: type}); } |
| 349 | + toClass(type: Type): Binding { |
| 350 | + if (!isType(type)) { |
| 351 | + throw new BaseException( |
| 352 | + `Trying to create a class binding but "${stringify(type)}" is not a class!`); |
| 353 | + } |
| 354 | + return new Binding(this.token, {toClass: type}); |
| 355 | + } |
348 | 356 |
|
349 | 357 | /** |
350 | 358 | * Binds a DI token to a value. |
@@ -416,8 +424,12 @@ export class BindingBuilder { |
416 | 424 | * expect(injector.get(String)).toEqual('Value: 3'); |
417 | 425 | * ``` |
418 | 426 | */ |
419 | | - toFactory(factoryFunction: Function, dependencies?: any[]): Binding { |
420 | | - return new Binding(this.token, {toFactory: factoryFunction, deps: dependencies}); |
| 427 | + toFactory(factory: Function, dependencies?: any[]): Binding { |
| 428 | + if (!isFunction(factory)) { |
| 429 | + throw new BaseException( |
| 430 | + `Trying to create a factory binding but "${stringify(factory)}" is not a function!`); |
| 431 | + } |
| 432 | + return new Binding(this.token, {toFactory: factory, deps: dependencies}); |
421 | 433 | } |
422 | 434 | } |
423 | 435 |
|
|
0 commit comments