c9 / architect

A simple yet powerful plugin system for large-scale node applications
MIT License
981 stars 129 forks source link

Unclear how to inject a node_modules module #46

Closed stephengardner closed 9 years ago

stephengardner commented 9 years ago

If I want to inject, for example, the promise npm module. How is this achieved? Forgive me if this is an obvious question, I've watched the YouTube video and read the documentation to no avail. Just getting my feet wet with different DI in Node

nightwing commented 9 years ago

@stephengardner just using "promise" for packagepath should work. non relative paths are handled by https://github.com/c9/architect/blob/master/architect.js#L191

stephengardner commented 9 years ago

Got it, somehow that's not working. Right now I'm requiring the npm modules in the architect modules themselves.

This doesn't work for me.

//...
var appConfig = [
        {
            packagePath : './app',
            config : config
        },
        {
            packagePath: "promise"
        },
        "./plugins/connections"
    ];
    var tree = architect.resolveConfig(appConfig, __dirname);
    architect.createApp(tree, function(err, Architect){
        if(err) {
            logger.error(err);
        }
        else {
            onCreateApp(Architect);
        }
    });
//...

I get TypeError: not a function from within node_modules/promise/lib/core.js

nightwing commented 9 years ago

That means promise isn't an architect plugin (doesn't provide like https://github.com/c9/architect/blob/master/demos/calculator/plugins/auth/auth.js#L1) in that case just use require("promise") directly

stephengardner commented 9 years ago

Got it, alright that's how I'm doing it, wasn't sure if that was the correct way, I guess it makes sense. The variations in all these DI frameworks made it a little confusing. Thanks