const Http                      = require('http');
const Controllers               = require('./controllers');
const Factories                 = require('./factories');
const Messages                  = require('./messages');
const Router                    = require('./router');
const Errors                    = require('./errors');

let Server = function () {
    if (!new.target) throw new Errors.Fatal('Server can not be called without creating instance.');

    this.componentsModules = {
        requestInterceptors: new Set(),
        responseInterceptors: new Set(),
        controllers: new Set(),
        factories: new Set()
    };

    this.router = Router;
    this.factories = Factories;
    this.controllers = Controllers;
    this.addComponent = addComponent;
    this.start = startServer;
    this.stop = stopServer;
};

const startServer = function (config) {

    componentsRegistration.call(this);

    this.server = Http.createServer(this.router.handle);

    this.server.listen(config.server.port, config.server.host, () => {
        console.log(`Server running at http://${config.server.host}:${config.server.port}/`);
    });
};

const stopServer = function () {
    this.server.close();
};

const addComponent = function (componentInfo) {
    Object.keys(componentInfo).forEach(
        type => componentInfo[type].forEach(
            path => this.componentsModules[type].add(path)
        ));
};

const componentsRegistration = function () {
    this.componentsModules.factories.forEach(model=> {
        this.factories.define(require(model));
    });

    this.componentsModules.requestInterceptors.forEach(interceptor => {
        Messages.request.addInterceptor(require(interceptor));
    });

    this.componentsModules.responseInterceptors.forEach(interceptor => {
        Messages.response.addInterceptor(require(interceptor));
    });

    this.componentsModules.controllers.forEach(controller=> {
        this.controllers.define(require(controller));
    });

};

module.exports = Server;
@@ -620,16 +620,46 @@
 ctories:
+ new Set(),%0A        bootstrap:
  new Set
@@ -1069,24 +1069,67 @@
 st, () =%3E %7B%0A
+        componentsBootstraping.call(this);%0A
         cons
@@ -2067,16 +2067,249 @@
 );%0A%0A%7D;%0A%0A
+const componentsBootstraping = function () %7B%0A    this.componentsModules.bootstrap.forEach(controller =%3E %7B%0A        const bootstrapFn = require(controller);%0A        (typeof bootstrapFn === 'function') && bootstrapFn(this);%0A    %7D);%0A%7D;%0A%0A
 module.e

Add bootstrap for modules