Skip to content

Commit

Permalink
fix(registrations): properly handle registrations that want to target…
Browse files Browse the repository at this point in the history
… different containers
  • Loading branch information
EisenbergEffect committed Oct 15, 2015
1 parent aac164f commit b60c103
Show file tree
Hide file tree
Showing 13 changed files with 965 additions and 961 deletions.
120 changes: 59 additions & 61 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,59 @@
System.config({
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [
"runtime",
"es7.decorators",
"es7.classProperties"
]
},
paths: {
"github:*": "jspm_packages/github/*",
"aurelia-dependency-injection/*": "dist/*",
"npm:*": "jspm_packages/npm/*"
},

map: {
"aurelia-logging": "github:aurelia/logging@0.8.0",
"aurelia-metadata": "github:aurelia/metadata@0.9.0",
"aurelia-pal": "github:aurelia/pal@0.2.0",
"babel": "npm:babel-core@5.1.13",
"babel-runtime": "npm:babel-runtime@5.1.13",
"core-js": "npm:core-js@1.2.1",
"github:aurelia/metadata@0.9.0": {
"aurelia-pal": "github:aurelia/pal@0.2.0",
"core-js": "npm:core-js@0.9.18"
},
"github:jspm/nodelibs-assert@0.1.0": {
"assert": "npm:assert@1.3.0"
},
"github:jspm/nodelibs-process@0.1.2": {
"process": "npm:process@0.11.2"
},
"github:jspm/nodelibs-util@0.1.0": {
"util": "npm:util@0.10.3"
},
"npm:assert@1.3.0": {
"util": "npm:util@0.10.3"
},
"npm:core-js@0.9.18": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"process": "github:jspm/nodelibs-process@0.1.2",
"systemjs-json": "github:systemjs/plugin-json@0.1.0"
},
"npm:core-js@1.2.1": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"process": "github:jspm/nodelibs-process@0.1.2",
"systemjs-json": "github:systemjs/plugin-json@0.1.0"
},
"npm:inherits@2.0.1": {
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:process@0.11.2": {
"assert": "github:jspm/nodelibs-assert@0.1.0"
},
"npm:util@0.10.3": {
"inherits": "npm:inherits@2.0.1",
"process": "github:jspm/nodelibs-process@0.1.2"
}
}
});
System.config({
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [
"runtime",
"es7.decorators",
"es7.classProperties"
]
},
paths: {
"github:*": "jspm_packages/github/*",
"aurelia-dependency-injection/*": "dist/*",
"npm:*": "jspm_packages/npm/*"
},

map: {
"aurelia-logging": "github:aurelia/logging@0.8.0",
"aurelia-metadata": "github:aurelia/metadata@0.9.0",
"aurelia-pal": "github:aurelia/pal@0.2.0",
"babel": "npm:babel-core@5.8.25",
"babel-runtime": "npm:babel-runtime@5.8.25",
"core-js": "npm:core-js@0.9.18",
"github:aurelia/metadata@0.9.0": {
"aurelia-pal": "github:aurelia/pal@0.2.0",
"core-js": "npm:core-js@0.9.18"
},
"github:jspm/nodelibs-assert@0.1.0": {
"assert": "npm:assert@1.3.0"
},
"github:jspm/nodelibs-process@0.1.2": {
"process": "npm:process@0.11.2"
},
"github:jspm/nodelibs-util@0.1.0": {
"util": "npm:util@0.10.3"
},
"npm:assert@1.3.0": {
"util": "npm:util@0.10.3"
},
"npm:babel-runtime@5.8.25": {
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:core-js@0.9.18": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"process": "github:jspm/nodelibs-process@0.1.2",
"systemjs-json": "github:systemjs/plugin-json@0.1.0"
},
"npm:inherits@2.0.1": {
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:process@0.11.2": {
"assert": "github:jspm/nodelibs-assert@0.1.0"
},
"npm:util@0.10.3": {
"inherits": "npm:inherits@2.0.1",
"process": "github:jspm/nodelibs-process@0.1.2"
}
}
});
164 changes: 82 additions & 82 deletions dist/amd/aurelia-dependency-injection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,121 +3,121 @@ declare module 'aurelia-dependency-injection' {
import { metadata, decorators } from 'aurelia-metadata';
import { AggregateError } from 'aurelia-pal';

/**
* An abstract resolver used to allow functions/classes to specify custom dependency resolution logic.
/**
* An abstract resolver used to allow functions/classes to specify custom dependency resolution logic.
*/
export class Resolver {

/**
* Called by the container to allow custom resolution of dependencies for a function/class.
* @param container The container to resolve from.
* @return Returns the resolved object.
/**
* Called by the container to allow custom resolution of dependencies for a function/class.
* @param container The container to resolve from.
* @return Returns the resolved object.
*/
get(container: Container): any;
}

/**
* Used to allow functions/classes to specify lazy resolution logic.
/**
* Used to allow functions/classes to specify lazy resolution logic.
*/
export class Lazy extends Resolver {

/**
* Creates an instance of the Lazy class.
* @param key The key to lazily resolve.
/**
* Creates an instance of the Lazy class.
* @param key The key to lazily resolve.
*/
constructor(key: any);

/**
* Called by the container to lazily resolve the dependency into a lazy locator function.
* @param container The container to resolve from.
* @return Returns a function which can be invoked at a later time to obtain the actual dependency.
/**
* Called by the container to lazily resolve the dependency into a lazy locator function.
* @param container The container to resolve from.
* @return Returns a function which can be invoked at a later time to obtain the actual dependency.
*/
get(container: Container): any;

/**
* Creates a Lazy Resolver for the supplied key.
* @param key The key to lazily resolve.
* @return Returns an insance of Lazy for the key.
/**
* Creates a Lazy Resolver for the supplied key.
* @param key The key to lazily resolve.
* @return Returns an insance of Lazy for the key.
*/
static of(key: any): Lazy;
}

/**
* Used to allow functions/classes to specify resolution of all matches to a key.
/**
* Used to allow functions/classes to specify resolution of all matches to a key.
*/
export class All extends Resolver {

/**
* Creates an instance of the All class.
* @param key The key to lazily resolve all matches for.
/**
* Creates an instance of the All class.
* @param key The key to lazily resolve all matches for.
*/
constructor(key: any);

/**
* Called by the container to resolve all matching dependencies as an array of instances.
* @param container The container to resolve from.
* @return Returns an array of all matching instances.
/**
* Called by the container to resolve all matching dependencies as an array of instances.
* @param container The container to resolve from.
* @return Returns an array of all matching instances.
*/
get(container: Container): any[];

/**
* Creates an All Resolver for the supplied key.
* @param key The key to resolve all instances for.
* @return Returns an insance of All for the key.
/**
* Creates an All Resolver for the supplied key.
* @param key The key to resolve all instances for.
* @return Returns an insance of All for the key.
*/
static of(key: any): All;
}

/**
* Used to allow functions/classes to specify an optional dependency, which will be resolved only if already registred with the container.
/**
* Used to allow functions/classes to specify an optional dependency, which will be resolved only if already registred with the container.
*/
export class Optional extends Resolver {

/**
* Creates an instance of the Optional class.
* @param key The key to optionally resolve for.
* @param [checkParent=false] Indicates whether or not the parent container hierarchy should be checked.
/**
* Creates an instance of the Optional class.
* @param key The key to optionally resolve for.
* @param [checkParent=false] Indicates whether or not the parent container hierarchy should be checked.
*/
constructor(key: any, checkParent?: boolean);

/**
* Called by the container to provide optional resolution of the key.
* @param container The container to resolve from.
* @return Returns the instance if found; otherwise null.
/**
* Called by the container to provide optional resolution of the key.
* @param container The container to resolve from.
* @return Returns the instance if found; otherwise null.
*/
get(container: Container): any;

/**
* Creates an Optional Resolver for the supplied key.
* @param key The key to optionally resolve for.
* @param [checkParent=false] Indicates whether or not the parent container hierarchy should be checked.
* @return Returns an insance of Optional for the key.
/**
* Creates an Optional Resolver for the supplied key.
* @param key The key to optionally resolve for.
* @param [checkParent=false] Indicates whether or not the parent container hierarchy should be checked.
* @return Returns an insance of Optional for the key.
*/
static of(key: any, checkParent?: boolean): Optional;
}

/**
* Used to inject the dependency from the parent container instead of the current one.
/**
* Used to inject the dependency from the parent container instead of the current one.
*/
export class Parent extends Resolver {

/**
* Creates an instance of the Parent class.
* @param key The key to resolve from the parent container.
/**
* Creates an instance of the Parent class.
* @param key The key to resolve from the parent container.
*/
constructor(key: any);

/**
* Called by the container to load the dependency from the parent container
* @param container The container to resolve the parent from.
* @return Returns the matching instance from the parent container
/**
* Called by the container to load the dependency from the parent container
* @param container The container to resolve the parent from.
* @return Returns the matching instance from the parent container
*/
get(container: Container): any;

/**
* Creates a Parent Resolver for the supplied key.
* @param key The key to resolve.
* @return Returns an insance of Parent for the key.
/**
* Creates a Parent Resolver for the supplied key.
* @param key The key to resolve.
* @return Returns an insance of Parent for the key.
*/
static of(key: any): Parent;
}
Expand Down Expand Up @@ -154,44 +154,44 @@ declare module 'aurelia-dependency-injection' {
invokeWithDynamicDependencies(container: any, fn: any, keys: any, deps: any): any;
}

/**
* Used to allow functions/classes to indicate that they should be registered as transients with the container.
/**
* Used to allow functions/classes to indicate that they should be registered as transients with the container.
*/
export class TransientRegistration {

/**
* Creates an instance of TransientRegistration.
* @param key The key to register as.
/**
* Creates an instance of TransientRegistration.
* @param key The key to register as.
*/
constructor(key: any);

/**
* Called by the container to register the annotated function/class as transient.
* @param container The container to register with.
* @param key The key to register as.
* @param fn The function to register (target of the annotation).
* @return The resolver that should to be used.
/**
* Called by the container to register the annotated function/class as transient.
* @param container The container to register with.
* @param key The key to register as.
* @param fn The function to register (target of the annotation).
* @return The resolver that should to be used.
*/
createResolver(container: Container, key: any, fn: Function): Resolver;
}

/**
* Used to allow functions/classes to indicate that they should be registered as singletons with the container.
/**
* Used to allow functions/classes to indicate that they should be registered as singletons with the container.
*/
export class SingletonRegistration {

/**
* Creates an instance of SingletonRegistration.
* @param key The key to register as.
/**
* Creates an instance of SingletonRegistration.
* @param key The key to register as.
*/
constructor(keyOrRegisterInChild: any, registerInChild?: boolean);

/**
* Called by the container to register the annotated function/class as a singleton.
* @param container The container to register with.
* @param key The key to register as.
* @param fn The function to register (target of the annotation).
* @return The resolver that should to be used.
/**
* Called by the container to register the annotated function/class as a singleton.
* @param container The container to register with.
* @param key The key to register as.
* @param fn The function to register (target of the annotation).
* @return The resolver that should to be used.
*/
createResolver(container: Container, key: any, fn: Function): Resolver;
}
Expand Down
5 changes: 3 additions & 2 deletions dist/amd/aurelia-dependency-injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-pal'], function (expo
var resolver = new StrategyResolver(1, fn);

if (!this.registerInChild && container !== container.root) {
container.root.registerResolver(this.key || key, resolver);
this.targetContainer = container.root;
}

return resolver;
Expand Down Expand Up @@ -390,7 +390,8 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-pal'], function (expo
resolver = new StrategyResolver(0, fn);
}

this.registerResolver(key === undefined ? fn : key, resolver);
var targetContainer = resolver.targetContainer || this;
targetContainer.registerResolver(key === undefined ? fn : key, resolver);
return resolver;
};

Expand Down
Loading

0 comments on commit b60c103

Please sign in to comment.