-
- Notifications
You must be signed in to change notification settings - Fork 338
Closed
Description
Can I use FactoryAggregate in a DeclarativeContainer, where I choose the proper factory via config? The following code does not work
from dependency_injector import containers, providers class A(object): name = "A" class B: name = "B" class C: def __init__(self, a_or_b): print(a_or_b.name) class IoC(containers.DeclarativeContainer): config = providers.Configuration('config') aggregate_factory = providers.FactoryAggregate(a=providers.Factory(A), b=providers.Factory(B)) # c_factory = providers.Factory(C, aggregate_factory('a')) # this works, but ignores the config c_factory = providers.Factory(C, aggregate_factory(config.a_or_b)) # this fails def main(): container = IoC(config={'a_or_b': 'a'}) c = container.c_factory() main()