1.1.14 • Published 7 years ago

plus.application v1.1.14

Weekly downloads
11
License
ISC
Repository
github
Last release
7 years ago

Application base: config + IoC container

The main goal of this package that loading app configuration and app services.

it uses 2 packages plus.container and plus.config and helps to manage application configuration and dependency injection. it has 2 parameters dir and env it loads configuration and container (services) from file system for some environment.

Usage

Configuration based on config npm package.

Dir

|-- default.js
|-- dev.js
|-- production.js
|-- container.js
|-- container_dev.js
|-- container_production.js
`-- container_test.js

Please take a look config for more details about configuration ways. It supports configuration in .js, .json, *.yml.

Confguration example
//default.js
module.exports = {
    port: 3000
}

App.js

// app.js example
    var Application = require('plus.application');

    var app = new Application({
        dir: __dirname,
        env: process.env.NODE_ENV || 'dev' // NODE_ENV or 'dev'
    });
    
    app.config.get('port'); // 3000
    app.container.get('myService1'); // it should be service, will explain soon.

    // app.config instanceof require('plus.config')
    // app.container instanceof require('plus.container')

container.js

// container.js example
module.exports = function (container) {
    var Class1 = function(){  }
    var Class2 = function(){ }

    container.register('myService1', Class1);
    container.register('myService2', Class2);
    
    // more effective way of course
    container.register('myService3', require('../services/MyService3'), ['myService1', 'myService2']);
    
}

more details about container configuration here plus.container its ES5/ES6 dependency injection container.

Wrap

wrapper example for app it adds config and container

        var express = require('express');
        var app = express();

        new Application({
            dir: __dirname,
            env: process.env.NODE_ENV || 'dev'
        }).wrap(app);

        app.config.get('port'); // 3000
        app.container.get('myService1') // new Class1
        //BUT: app.container.get('myService1') === app.container.get('myService1')
        
        // nested access
        app.container.get('config/port') // 3000
        
        // for example
        app.listen(app.container.get('config/port'))
        // same thing is: app.listen(app.config.get('port'))

Please take a look on:

Alternative configuration way with json(s) only.

This configuration based on nconf and this is alternative way.

Dir
|-- config.json // main config
|-- config_dev.json // env config
|-- config_prod.json
|-- config_test.json
|-- container.js // main container
|-- container_dev.js // env container
|-- container_production.js
`-- container_test.js
config.json

config.json example

{
    "port": 3000
}

Take a look nconf for more info. if you need this way.

Create shortcut

    var app = require('plus.application').create({
         dir: __dirname,
         env: process.env.NODE_ENV || 'dev' // NODE_ENV or 'dev'
     });

its equal to

    var app = new Application({
        dir: __dirname,
        env: process.env.NODE_ENV || 'dev' // NODE_ENV or 'dev'
    });

Have a fun and manage your applications! +1G Team

Be happy!

1.1.14

7 years ago

1.1.13

8 years ago

1.1.12

8 years ago

1.1.11

8 years ago

1.1.10

8 years ago

1.1.9

8 years ago

1.1.8

8 years ago

1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago