DI: Alternative approach to supply DI context to Components
lhaze opened this issue · 1 comments
lhaze commented
Up to now, binding a component with the Dependency Injection context is made by assuming that every Component has its __init__
fulfill the signature of (container: Container, **kwargs) -> None
. This results in the following inconveniences:
- forces
__init__
's argument structure which is one more thing to remember and may have an impact on inheriting a Component from extraneous classes - doesn't supply the qualifier to Component that was created for; this might be a problem, e.g., in #60 (DAO doesn't have a ground to know structure being modeled)
lhaze commented
Fixed. Now, an instance constructed has its context under:
from pca.utils.dependency_injection import get_di_context
di_context: DIContext = get_di_context(instance)
qualifier = di_context.qualifier