luin/express-di — pull request #8 by Bringer128 (2014-11-26 12:46:03+00:00)
Title: Naive implementation of nested factory dependencies

Hi,

This pull request is intended to be a strawman implementation of having factory dependencies. It creates a wrapper function for the factory functions lazily.

This implementation has the following obvious problems:
1. It's possible to create an infinite recursive loop with cyclic dependencies
2. It will not perform well - this implementation wires up dependencies lazily and doesn't cache them.

I would like to start a discussion on more preferable implementations to this.

Of course, if you're not interested say so and I'll run with my own fork. :)

The goal I'm trying to achieve is to have code like this:

```javascript
var express = require('express');
require('express-di');

var app = express();

app.factory('foo', function(req, res, next) {
next(null, 'foo');
});

app.factory('bar', function(req, res, next) {
next(null, 'bar');
});

app.factory('foobar', function(foo, bar, req, res, next) {
next(null, {foo: foo, bar: bar});
});

app.get('/', function(foobar, req, res) {
res.json(foobar);
});

require('http').createServer(app).listen(process.env.PORT);
```