@@ -29,9 +29,9 @@ function constructResolvingPath(keys: any[]): string {
|
||||
|
||||
|
||||
/**
|
||||
* Base class for all errors arising from misconfigured bindings.
|
||||
* Base class for all errors arising from misconfigured providers.
|
||||
*/
|
||||
export class AbstractBindingError extends BaseException {
|
||||
export class AbstractProviderError extends BaseException {
|
||||
/** @internal */
|
||||
message: string;
|
||||
|
||||
@@ -63,7 +63,7 @@ export class AbstractBindingError extends BaseException {
|
||||
|
||||
/**
|
||||
* Thrown when trying to retrieve a dependency by `Key` from {@link Injector}, but the
|
||||
* {@link Injector} does not have a {@link Binding} for {@link Key}.
|
||||
* {@link Injector} does not have a {@link Provider} for {@link Key}.
|
||||
*
|
||||
* ### Example ([live demo](http://plnkr.co/edit/vq8D3FRB9aGbnWJqtEPE?p=preview))
|
||||
*
|
||||
@@ -75,7 +75,7 @@ export class AbstractBindingError extends BaseException {
|
||||
* expect(() => Injector.resolveAndCreate([A])).toThrowError();
|
||||
* ```
|
||||
*/
|
||||
export class NoBindingError extends AbstractBindingError {
|
||||
export class NoProviderError extends AbstractProviderError {
|
||||
constructor(injector: Injector, key: Key) {
|
||||
super(injector, key, function(keys: any[]) {
|
||||
var first = stringify(ListWrapper.first(keys).token);
|
||||
@@ -91,8 +91,8 @@ export class NoBindingError extends AbstractBindingError {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* bind("one").toFactory((two) => "two", [[new Inject("two")]]),
|
||||
* bind("two").toFactory((one) => "one", [[new Inject("one")]])
|
||||
* provide("one", {asFactory: (two) => "two", deps: [[new Inject("two")]]}),
|
||||
* provide("two", {asFactory: (one) => "one", deps: [[new Inject("one")]]})
|
||||
* ]);
|
||||
*
|
||||
* expect(() => injector.get("one")).toThrowError();
|
||||
@@ -100,7 +100,7 @@ export class NoBindingError extends AbstractBindingError {
|
||||
*
|
||||
* Retrieving `A` or `B` throws a `CyclicDependencyError` as the graph above cannot be constructed.
|
||||
*/
|
||||
export class CyclicDependencyError extends AbstractBindingError {
|
||||
export class CyclicDependencyError extends AbstractProviderError {
|
||||
constructor(injector: Injector, key: Key) {
|
||||
super(injector, key, function(keys: any[]) {
|
||||
return `Cannot instantiate cyclic dependency!${constructResolvingPath(keys)}`;
|
||||
@@ -163,7 +163,7 @@ export class InstantiationError extends WrappedException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown when an object other then {@link Binding} (or `Type`) is passed to {@link Injector}
|
||||
* Thrown when an object other then {@link Provider} (or `Type`) is passed to {@link Injector}
|
||||
* creation.
|
||||
*
|
||||
* ### Example ([live demo](http://plnkr.co/edit/YatCFbPAMCL0JSSQ4mvH?p=preview))
|
||||
@@ -172,10 +172,10 @@ export class InstantiationError extends WrappedException {
|
||||
* expect(() => Injector.resolveAndCreate(["not a type"])).toThrowError();
|
||||
* ```
|
||||
*/
|
||||
export class InvalidBindingError extends BaseException {
|
||||
constructor(binding) {
|
||||
super("Invalid binding - only instances of Binding and Type are allowed, got: " +
|
||||
binding.toString());
|
||||
export class InvalidProviderError extends BaseException {
|
||||
constructor(provider) {
|
||||
super("Invalid provider - only instances of Provider and Type are allowed, got: " +
|
||||
provider.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,20 +246,20 @@ export class OutOfBoundsError extends BaseException {
|
||||
|
||||
// TODO: add a working example after alpha38 is released
|
||||
/**
|
||||
* Thrown when a multi binding and a regular binding are bound to the same token.
|
||||
* Thrown when a multi provider and a regular provider are bound to the same token.
|
||||
*
|
||||
* ### Example
|
||||
*
|
||||
* ```typescript
|
||||
* expect(() => Injector.resolveAndCreate([
|
||||
* new Binding("Strings", {toValue: "string1", multi: true}),
|
||||
* new Binding("Strings", {toValue: "string2", multi: false})
|
||||
* new Provider("Strings", {toValue: "string1", multi: true}),
|
||||
* new Provider("Strings", {toValue: "string2", multi: false})
|
||||
* ])).toThrowError();
|
||||
* ```
|
||||
*/
|
||||
export class MixingMultiBindingsWithRegularBindings extends BaseException {
|
||||
constructor(binding1, binding2) {
|
||||
super("Cannot mix multi bindings and regular bindings, got: " + binding1.toString() + " " +
|
||||
binding2.toString());
|
||||
export class MixingMultiProvidersWithRegularProvidersError extends BaseException {
|
||||
constructor(provider1, provider2) {
|
||||
super("Cannot mix multi providers and regular providers, got: " + provider1.toString() + " " +
|
||||
provider2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@ export {TypeLiteral} from './type_literal';
|
||||
* injector to store created objects in a more efficient way.
|
||||
*
|
||||
* `Key` should not be created directly. {@link Injector} creates keys automatically when resolving
|
||||
* bindings.
|
||||
* providers.
|
||||
*/
|
||||
export class Key {
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,7 @@ import {CONST, CONST_EXPR, stringify, isBlank, isPresent} from "angular2/src/cor
|
||||
* }
|
||||
*
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* bind("MyEngine").toClass(Engine),
|
||||
* provide("MyEngine", {asClass: Engine}),
|
||||
* Car
|
||||
* ]);
|
||||
*
|
||||
@@ -212,7 +212,7 @@ export class SkipSelfMetadata {
|
||||
*
|
||||
* @Component({
|
||||
* selector: 'parent-cmp',
|
||||
* bindings: [HostService]
|
||||
* providers: [HostService]
|
||||
* })
|
||||
* @View({
|
||||
* template: `
|
||||
@@ -225,7 +225,7 @@ export class SkipSelfMetadata {
|
||||
*
|
||||
* @Component({
|
||||
* selector: 'app',
|
||||
* bindings: [OtherService]
|
||||
* providers: [OtherService]
|
||||
* })
|
||||
* @View({
|
||||
* template: `
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import {CONST} from 'angular2/src/core/facade/lang';
|
||||
|
||||
/**
|
||||
* Creates a token that can be used in a DI Binding.
|
||||
* Creates a token that can be used in a DI Provider.
|
||||
*
|
||||
* ### Example ([live demo](http://plnkr.co/edit/Ys9ezXpj2Mnoy3Uc8KBp?p=preview))
|
||||
*
|
||||
* ```typescript
|
||||
* var t = new OpaqueToken("binding");
|
||||
* var t = new OpaqueToken("value");
|
||||
*
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* bind(t).toValue("bindingValue")
|
||||
* provide(t, {asValue: "providedValue"})
|
||||
* ]);
|
||||
*
|
||||
* expect(injector.get(t)).toEqual("bindingValue");
|
||||
* ```
|
||||
*
|
||||
* Using an `OpaqueToken` is preferable to using strings as tokens because of possible collisions
|
||||
* caused by multiple bindings using the same string as two different tokens.
|
||||
* caused by multiple providers using the same string as two different tokens.
|
||||
*
|
||||
* Using an `OpaqueToken` is preferable to using an `Object` as tokens because it provides better
|
||||
* error messages.
|
||||
|
||||
+160
-105
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user