Open chbndrhnns opened 3 years ago
According to my experiences with the library, this seems not possible. Is it something you see as valuable to have, @rmk135?
Hi @chbndrhnns ,
Thanks for sharing the use case. Yes, I think you can be something like:
class Repositories(containers.DeclarativeContainer):
adapters: Adapters = containers.DependenciesContainer(instanceof= Adapters)
repo = providers.Factory(
Repo, adapter=adapters.db_adapter
)
I'll add it to the backlog.
Your example is not working for me as containers
(line 2) does not seem to have a DependenciesContainer
. In version 4.37, only providers
has DependenciesContainer
.
Also, when I try to run Repositories()
from the snippet below, it fails:
class Repositories(containers.DeclarativeContainer):
adapters: Adapters = providers.DependenciesContainer(instance_of=Adapters)
repo = providers.Factory(Repo, adapter=adapters.db_adapter)
Error:
src/dependency_injector/containers.pyx:742: in dependency_injector.containers.DeclarativeContainer.__new__
???
src/dependency_injector/containers.pyx:392: in dependency_injector.containers.DynamicContainer.load_config
???
src/dependency_injector/containers.pyx:193: in traverse
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E AttributeError: type object 'Adapters' has no attribute 'related'
src/dependency_injector/providers.pyx:4813: AttributeError
Yeah, same issue for me.
@rmk135 i am coming back to this issue now and then. Do you have any idea what to do?
I am trying to re-create an onion-layer architecture with the dependency injector library. Here is a snippet:
Can I make dependency-injector check the provided container for
adapters
and reject invalid types?