jaredhanson / electrolyte

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

Does IoC.use have to return a function? #75

Closed bajankristof closed 3 years ago

bajankristof commented 6 years ago

Hi!

I'll be honest here, I did not dig deep into the module to find out the answer to my question so here we go:

const IoC = require('electrolyte')

IoC.use(
    IoC.dir('app')
)

(async () => {
    const dep = await IoC.create('dependency')
    dep.run()
})()

If you try this, it will throw an error because IoC.use returns a function so the interpreter will try to run it with the async anonymous function as an argument. Obviously one could evade this issue by just putting a semicolon at the end of IoC.use but in a lot of workspaces the coding style requires us not to write those at the end of the lines.

I hope that makes sense!

Stradivario commented 6 years ago

Hello please take a look at this project it may be useful for you!

I have created Reactive Extension Dependency Injection for Typescript you can check it out

https://github.com/rxdi/core

Here is a GraphQL Framework build on top of it

https://github.com/Stradivario/gapi

Njoy! :)