thiagobustamante / typescript-ioc

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

Option to have target instance or (at least) target class name in factory context #72

Open koldoon opened 3 years ago

koldoon commented 3 years ago

I've got a proposal to include target instance (which I suppose is not possible since there isn't async resolution logic yet) or target Class (Type) name (I mean, TargetClass.constructor.name or even TargetClass.constructor) in factory binder context.

One of the most popular commonly used dependency is Logger, but the logger often include extra params, like Category or Module Name, that describes the place module logs comes from. Conventionally it looks like this:

export class SomeService {
    private readonly logger: Logger = Log.createLogger('SomeService');
}

So, with IoC I would like to have smth like this:

But currently there is no way to get any suitable target instance info within factory context.