Dependency injection framework is constructing the object first and then injecting the dependency which is incorrect.
def requires(*dependencies):
"""Inject specified dependencies from the registry into the instance."""
def wrapper(self, *args, **kwargs):
"""Inject each dependency from the registry."""
self.__wrapped_init__(*args, **kwargs) ----------------------> Constructs object First
for dependency in self._dependencies: ----------------------> Inject dependency Second
if dependency not in REGISTRY:
raise UnresolvableDependencyException(dependency)
setattr(self, dependency, REGISTRY[dependency])
It would be better to inject the dependency first and then construct the object, so that the dependency is available during object construction.
Is there a DI framework for Python that does this cleanly?