thiagobustamante / typescript-ioc

A Lightweight annotation-based dependency injection container for typescript.
MIT License
526 stars 64 forks source link

What case is meaningful for @AutoWired except @Singleton? #49

Closed jinsankim closed 4 years ago

jinsankim commented 5 years ago

Please could you explain or show a case why @AutoWired is meaningful except @Singleton?

DGrudzynskyi commented 5 years ago

It feels like this is a perfect place for handling parameters-injection-at-rest, hovewer it doesn't looks like at this moment autowired is doing anything like this (unless i am missing something).

What i means is handling of the scenario below by passing PersonDAO from container

class Person(attributes: any, dao?: PersonDAO) {

}

const valeriy = new Person({name: 'valeriy'})
thiagobustamante commented 4 years ago

AutoWired replaces the original class constructor to avoid that new instances are created directly through the class constructor (without call the ioc container). I believe that it only makes sense if the scope used to manage the instances is diferent from Scope.Local. The library only includes the Local and Singleton scopes, but is possible to use a custom scope. An express application, for example, could use express-http-context to create a RequestScope,