Skip to content

Commit

Permalink
chore(all): prepare release 0.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Feb 28, 2015
1 parent 25e924c commit b488c77
Show file tree
Hide file tree
Showing 15 changed files with 1,096 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-dependency-injection",
"version": "0.4.3",
"version": "0.4.4",
"description": "A lightweight, extensible dependency injection container for JavaScript.",
"keywords": [
"aurelia",
Expand Down
132 changes: 130 additions & 2 deletions dist/amd/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,40 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export

var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };

var Metadata = _aureliaMetadata.Metadata;
var Resolver = _metadata.Resolver;
var Registration = _metadata.Registration;
var isClass = _util.isClass;


var emptyParameters = Object.freeze([]);

/**
* A lightweight, extensible dependency injection container.
*
* @class Container
* @constructor
*/

var Container = exports.Container = (function () {
function Container(constructionInfo) {
_classCallCheck(this, Container);

this.constructionInfo = constructionInfo || new Map();
this.entries = new Map();
this.root = this;
}

_prototypeProperties(Container, null, {
supportAtScript: {

/**
* Add support for AtScript RTTI according to spec at http://www.atscript.org
*
* @method useAtScript
*/

value: function supportAtScript() {
this.addParameterInfoLocator(function (fn) {
var parameters = fn.parameters,
Expand All @@ -42,6 +59,14 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
addParameterInfoLocator: {

/**
* Adds an additional location to search for constructor parameter type info.
*
* @method addParameterInfoLocator
* @param {Function} locator Configures a locator function to use when searching for parameter info. It should return undefined if no parameter info is found.
*/

value: function addParameterInfoLocator(locator) {
if (this.locateParameterInfoElsewhere === undefined) {
this.locateParameterInfoElsewhere = locator;
Expand All @@ -57,6 +82,15 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
registerInstance: {

/**
* Registers an existing object instance with the container.
*
* @method registerInstance
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Object} instance The instance that will be resolved when the key is matched.
*/

value: function registerInstance(key, instance) {
this.registerHandler(key, function (x) {
return instance;
Expand All @@ -66,6 +100,15 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
registerTransient: {

/**
* Registers a type (constructor function) such that the container returns a new instance for each request.
*
* @method registerTransient
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Function} [fn] The constructor function to use when the dependency needs to be instantiated.
*/

value: function registerTransient(key, fn) {
fn = fn || key;
this.registerHandler(key, function (x) {
Expand All @@ -76,6 +119,15 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
registerSingleton: {

/**
* Registers a type (constructor function) such that the container always returns the same instance for each request.
*
* @method registerSingleton
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Function} [fn] The constructor function to use when the dependency needs to be instantiated.
*/

value: function registerSingleton(key, fn) {
var singleton = null;
fn = fn || key;
Expand All @@ -87,6 +139,15 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
autoRegister: {

/**
* Registers a type (constructor function) by inspecting its registration annotations. If none are found, then the default singleton registration is used.
*
* @method autoRegister
* @param {Function} fn The constructor function to use when the dependency needs to be instantiated.
* @param {Object} [key] The key that identifies the dependency at resolution time; usually a constructor function.
*/

value: function autoRegister(fn, key) {
var registration;

Expand All @@ -106,6 +167,14 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
autoRegisterAll: {

/**
* Registers an array of types (constructor functions) by inspecting their registration annotations. If none are found, then the default singleton registration is used.
*
* @method autoRegisterAll
* @param {Function[]} fns The constructor function to use when the dependency needs to be instantiated.
*/

value: function autoRegisterAll(fns) {
var i = fns.length;
while (i--) {
Expand All @@ -116,13 +185,31 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
registerHandler: {

/**
* Registers a custom resolution function such that the container calls this function for each request to obtain the instance.
*
* @method registerHandler
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Function} handler The resolution function to use when the dependency is needed. It will be passed one arguement, the container instance that is invoking it.
*/

value: function registerHandler(key, handler) {
this.getOrCreateEntry(key).push(handler);
},
writable: true,
configurable: true
},
get: {

/**
* Resolves a single instance based on the provided key.
*
* @method get
* @param {Object} key The key that identifies the object to resolve.
* @return {Object} Returns the resolved instance.
*/

value: function get(key) {
var entry;

Expand Down Expand Up @@ -157,8 +244,18 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
getAll: {

/**
* Resolves all instance registered under the provided key.
*
* @method getAll
* @param {Object} key The key that identifies the objects to resolve.
* @return {Object[]} Returns an array of the resolved instances.
*/

value: function getAll(key) {
var _this = this;

var entry;

if (key === null || key === undefined) {
Expand All @@ -183,8 +280,19 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
hasHandler: {

/**
* Inspects the container to determine if a particular key has been registred.
*
* @method hasHandler
* @param {Object} key The key that identifies the dependency at resolution time; usually a constructor function.
* @param {Boolean} [checkParent=false] Indicates whether or not to check the parent container hierarchy.
* @return {Boolean} Returns true if the key has been registred; false otherwise.
*/

value: function hasHandler(key) {
var checkParent = arguments[1] === undefined ? false : arguments[1];

if (key === null || key === undefined) {
throw new Error("key cannot be null or undefined.");
}
Expand All @@ -195,6 +303,14 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
createChild: {

/**
* Creates a new dependency injection container whose parent is the current container.
*
* @method createChild
* @return {Container} Returns a new container instance parented to this.
*/

value: function createChild() {
var childContainer = new Container(this.constructionInfo);
childContainer.parent = this;
Expand All @@ -206,6 +322,15 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
configurable: true
},
invoke: {

/**
* Invokes a function, recursively resolving its dependencies.
*
* @method invoke
* @param {Function} fn The function to invoke with the auto-resolved dependencies.
* @return {Object} Returns the instance resulting from calling the function.
*/

value: function invoke(fn) {
var info = this.getOrCreateConstructionInfo(fn),
keys = info.keys,
Expand Down Expand Up @@ -296,5 +421,8 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export

return Container;
})();
exports.__esModule = true;

Object.defineProperty(exports, "__esModule", {
value: true
});
});
10 changes: 8 additions & 2 deletions dist/amd/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
define(["exports", "aurelia-metadata", "./metadata", "./container"], function (exports, _aureliaMetadata, _metadata, _container) {
"use strict";

/**
* A lightweight, extensible dependency injection container for JavaScript.
*
* @module dependency-injection
*/
var Metadata = _aureliaMetadata.Metadata;
var Transient = _metadata.Transient;
var Singleton = _metadata.Singleton;
Expand All @@ -14,8 +19,9 @@ define(["exports", "aurelia-metadata", "./metadata", "./container"], function (e
exports.Parent = _metadata.Parent;
exports.Container = _container.Container;


Metadata.configure.classHelper("transient", Transient);
Metadata.configure.classHelper("singleton", Singleton);
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
});
Loading

0 comments on commit b488c77

Please sign in to comment.