scottcorgan/Injector — pull request #36 by dragonprojects (2014-07-22 17:35:36+00:00)
Title: Improvement: Aliases for modules for example to support modules from "node_modules" with special characters

Hi,

my first pull request, but I hope it will works to send you a little improvement to your greate project. :)

## Introduction

The injector allows to load modules from "node_modules" per inject and per defining as dependency.
So:
```javascript
var dependency = require('dependency');
exports.module = function () {};
```

Is the same as:
```javascript
exports.module = function (inject) {
var dependency = inject('dependency');
};
```

And the same as:
```javascript
exports.module = function (dependency) {};
```

## Problem

But the problem are modules with special characters in the name, like "body-parser" (connector extension for express).

So this will not work, its a syntax error:
```javascript
exports.module = function (body-parser) {};
```

## Solution

Cause of this problem I add the possibility to define aliases for the Injector.

So with this feature you can add aliases to the injector configuration:
```javascript
Injector.create('', {
aliases: {
bodyParser: 'body-parser'
}
});
```

And now use the alias as dependency for modules:
```javascript
exports.module = function (bodyParser) {};
```

## Implementation

I add the aliases to the register method and replace the names in the dependency configuration of the modules. This was the only central location I found to check and replace the aliases for both types of modules (parsed modules and modules from "node_modules").

But if you find a better location feel free. :)