Skip to content

Provide injectee context to factory [aka InjectionPoint] #460

Open
@mxab

Description

@mxab

Hi,

Would be cool if there would be a provider method that would be provided with the target information the provided element is injected to (...sorry for that funny sentence.. )

For example something like this:

@attr.s(auto_attribs=True)
class MyService:
   log: Logger


def get_logger(target) -> Logger: # target could be the class for example
 return logging.getLogger(target.__name__)
 
 
class Container(DC):
 logger_factory = providers.SomeSpecialInjecteeAwareFactory(get_logger)
 service = providers.Singleton(MyService, log =  logger_factory)

The idea relates to Spring's InjectionPoint
https://fatihdirlikli.wordpress.com/2016/11/22/logger-injection-with-injectionpoint/

Does this make sense?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions