inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.34k stars 719 forks source link

Inject contextually with class name #570

Closed Aboisier closed 7 years ago

Aboisier commented 7 years ago

Hi,

I am currently trying to inject loggers in different classes. I am using log4js. My problem is the following:
I would like to categorize each injected logger the name of the target class (the one it's being injected into).

However, I have not been able to retrieve the class name. Is there any way of doing this?

container.bind<log4js.Logger>(Types.Logger).toDynamicValue(context => {
    let className = context....?; // Finds class name
    return log4js.getLogger(className );
});

Thank you! Antoine

Aboisier commented 7 years ago

Related to : https://github.com/inversify/InversifyJS/issues/576

remojansen commented 7 years ago

Hi @Aboisier can you please share your feedback in #576 ? I will close this issue so we can track it in the other one.

Aboisier commented 7 years ago

I think the other issue is descriptive enough, I don't have anything to add for now. I think you can close this one. Thanks @remojansen !