'use strict';

const EventEmitter = require('events').EventEmitter;
const ServiceLocator = require('catberry-locator');
const CollectionFinder = require('./finders/CollectionsFinder');
const CollectionsLoader = require('./loaders/CollectionsLoader');
const ContextFactory = require('./context/ContextFactory');
const RoutesFactory = require('./router/RoutesFactory');
const RequestRouter = require('./router/RequestRouter');
const FormatterProvider = require('./FormatterProvider');
const Server = require('./Server');
const errors = require('./errors');
const Watcher = require('./Watcher');
const packageJson = require('../package.json');
const path = require('path');
const definedRoutesPath = path.join(process.cwd(), 'routes');

class Substance {

  /**
   * Create instance of Substance
   *
   * @param config
   */
  constructor(config = {}) {

    /**
     * Service Locator
     * @type {ServiceLocator}
     */
    this.locator = new ServiceLocator();

    /**
     * HttpError constructors
     *
     * @type {Object}
     */
    this.errors = errors;

    /**
     * Current version
     *
     * @type {string}
     */
    this.version = packageJson.version;

    /**
     * Current config
     *
     * @type {Object}
     * @private
     */
    this._config = config;

    /**
     * Global event bus
     *
     * @type {EventEmitter}
     * @private
     */
    this.events = null;

    this._configure();
  }

  /**
   * Registration instances in service locator
   *
   * @private
   */
  _configure() {
    this.events = new EventEmitter();
    this.events.setMaxListeners(0);

    this.locator.registerInstance('errors', errors);
    this.locator.registerInstance('config', this._config);
    this.locator.registerInstance('events', this.events);
    this.locator.registerInstance('definedRoutes', require(definedRoutesPath));

    this.locator.register('watcher', Watcher, true);
    this.locator.register('collectionsFinder', CollectionFinder, true);
    this.locator.register('collectionsLoader', CollectionsLoader, true);
    this.locator.register('contextFactory', ContextFactory, true);
    this.locator.register('routesFactory', RoutesFactory, true);
    this.locator.register('requestRouter', RequestRouter, true);
    this.locator.register('formatterProvider', FormatterProvider, true);

    // Initialization watcher
    this.locator.resolve('watcher');
  }

  /**
   * Create http server
   *
   * @return {Server} Instance of http server
   */
  createServer() {
    return new Server(this.locator);
  }

  /**
   * Errors export
   */
  static get errors() {
    return errors;
  }
}

module.exports = Substance;

@@ -730,24 +730,142 @@
 ');%0A
-%0Aclass Substance
+let routeDefinitions;%0A%0Atry %7B%0A  routeDefinitions = require(definedRoutesPath);%0A%7D catch (e) %7B%0A  routeDefinitions = %7B%7D;%0A%7D%0A%0Aclass Restocat
  %7B%0A%0A
@@ -1937,33 +1937,23 @@
 ', r
-equire(definedRoutesPath)
+outeDefinitions
 );%0A%0A
@@ -2739,19 +2739,18 @@
 ports = 
-Substance
+Restocat
 ;%0A

Rename main class from "Substance" to "Restocat" and improved the registration of routes