- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 335
Open
Labels
Description
I am trying to re-create an onion-layer architecture with the dependency injector library. Here is a snippet:
from dependency_injector import containers, providers
class DbAdapter:
def get_all(self):
return []
class Repo:
def __init__(self, adapter):
self._adapter = adapter
class Adapters(containers.DeclarativeContainer):
db_adapter = providers.Singleton(
DbAdapter
)
class Repositories(containers.DeclarativeContainer):
adapters: Adapters = containers.DependenciesContainer()
repo = providers.Factory(
Repo, adapter=adapters.db_adapter
)
Can I make dependency-injector check the provided container for adapters
and reject invalid types?
rasmus91 and warvariuc
Activity
chbndrhnns commentedon Oct 21, 2021
According to my experiences with the library, this seems not possible. Is it something you see as valuable to have, @rmk135?
rmk135 commentedon Nov 8, 2021
Hi @chbndrhnns ,
Thanks for sharing the use case. Yes, I think you can be something like:
I'll add it to the backlog.
chbndrhnns commentedon Nov 8, 2021
Your example is not working for me as
containers
(line 2) does not seem to have aDependenciesContainer
. In version 4.37, onlyproviders
hasDependenciesContainer
.Also, when I try to run
Repositories()
from the snippet below, it fails:Error:
rowan-maclachlan commentedon Mar 24, 2022
Yeah, same issue for me.
chbndrhnns commentedon Oct 18, 2022
@rmk135 i am coming back to this issue now and then. Do you have any idea what to do?