Open cit-alexf opened 11 months ago
Supporting this would be great. This is probably the best dependency injection package for python but this problem with abstract methods (basically interfaces) does not allow for dependency inversion, and they both, injection and inversion, should always be together for a SOLID implementation.
@AyrtonAlbuquerque thanks.
I will gladly accept a PR if somebody finds a solution and fixes it 🙂
Hello.
I'm trying to use python-inject 5.1.0 and I'm unable to inject a class implemented into an abstract class.
class JobGateway: @abstractmethod def get_by_id(self, id: str): pass
class JobGatewayImpl(JobGateway): @inject.autoparams() def init(self, db: Database): self.collection = db["jobs"]
class MessageProcessor: @inject.autoparams() def init( self, job_gateway: JobGateway ) -> None: self.job_gateway = job_gateway
My optional configuration:
binder.bind_to_constructor(JobGateway, lambda: inject.instance(JobGatewayImpl))
When I get a MessageProcessor instance, job_gateway does not get the JobGatewayImpl implementation.
processor: MessageProcessor = inject.instance(MessageProcessor)
But, when I try to get the instance directly, JobGatewayImpl is obtained successfully.
j2: JobGateway = inject.instance(JobGateway)
Why is the JobGatewayImpl implementation not injected into the processor?