c9 / architect

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

Is this possible to add namespaces for services? #15

Closed bmatusiak closed 11 years ago

bmatusiak commented 11 years ago

Ok quick scenario

Lets say i want to provide a service as "db.mongo" and "db.mysql"

ok

lets say another plugin "app.users" consumes "db"

is it possible to render a object like

{db:{
mongo:$mongo_obj,
mysql:$mysql_obj
}}

but! lets say i only want to consume "db.mysql"

{db:{
mysql:$mysql_obj
}}
janjongboom commented 11 years ago

One plugin can provide multiple services, that should do what you need already.

In plugins/db/package.json: "provides": [ "db.mongo", "db.mysql" ]

And in plugins/db/db-plugin.js: register(null, { "db.mongo": {}, "db.mysql": {} }).

And now app.users can just consume db.mysql. But it will come in as imports["db.mysql"].

jameswyse commented 11 years ago

I've a similar problem, I want to have a namespace called models so I can create models and use them all at once in my API plugin. I'd like my API to consume all the models without knowing their names to allow the end user to write their own model plugins.

For example:

Plugins/model-user/             Provides: models.user
Plugins/model-post/             Provides: models.post
Plugins/user-defined-model      Provides: models.whoknows
Plugins/api/                    Provides: API, Consumes: models

I could make a Model plugin to collect the models in to a single object, but it feels a bit hackish. What do you think?

bmatusiak commented 11 years ago

@jameswyse i found that you can run architect inside a plugin to its self

plugins/db/package.json

"provides": [ "db" ]

plugins/db/db-plugin.js

architect.createApp(config, function (err, DB) {
  register(null, {
        db : DB.services
    });
});

basically nesting architect

jameswyse commented 11 years ago

Oh, that's an interesting solution! I'll give it a go.

bmatusiak commented 11 years ago

@jameswyse Cool Let me know how it goes, your answer will be intriguing

janjongboom commented 11 years ago

@bmatusiak Interesting approach!

bmatusiak commented 11 years ago

@janjongboom thanks for the :thumbsup: