jaredhanson / electrolyte

Elegant dependency injection for Node.js.
MIT License
564 stars 61 forks source link

Using it with class #69

Closed fattouchsquall closed 7 years ago

fattouchsquall commented 7 years ago

Hello,

I've wrote my class as this:

class Application {
  /**
   * Creates a new Application
   */
  constructor(express, router, config) {
    this.app = express();
    this.router = router;
    this.setting = config;
  }
}

module.exports = Application;

module.exports['@require'] = [
  'express',
  'router',
  'config'
]

In my entry point, i have this:

let IoC = require('electrolyte');
IoC.use(IoC.node_modules());
IoC.use(IoC.dir('src/'));
IoC.use(IoC.dir('app/'));

But all the dependencies are undefined. Can you help please?

fattouchsquall commented 7 years ago

Hello,

I resolved my problem, i must create the main entry point of my application as below:

IoC.create('http-application')
    .then((httpApplication) => {
      httpApplication.boot();
      if (httpApplication.settings.environment === 'dev') {
        httpApplication.startServer();
      }
    })
    .catch((e) => console.log(e));
rcbop commented 6 years ago

@fattouchsquall can you provide the boot() and startServer() code? Having trouble making it work with Class and Async/Await