-
-
Notifications
You must be signed in to change notification settings - Fork 337
Closed
Description
Hi, I wonder why the following snippet breaks?
import logging
import dependency_injector.containers as dic
import dependency_injector.providers as dip
from collections import namedtuple
GuBar = namedtuple( "GuBar", [ "product_id" ] )
Milk = namedtuple( "Milk", [ "product_id" ] )
class CommonServices( dic.DeclarativeContainer ):
logger = dip.Singleton( logging.Logger, name = None )
staples = dip.Callable(
lambda id: (
dip.Singleton( logging.Logger, name = id )(),
dip.Singleton( GuBar, product_id = id )(),
dip.Singleton( Milk, product_id = id )()
# more products that need id for initialization
)
)
ShoppingCart = namedtuple( "ShoppingCart", [ "staples" ] )
class AgentServices( dic.DeclarativeContainer ):
common_services = dip.DependenciesContainer()
shopping_cart = dip.Factory( ShoppingCart, staples = dip.Factory( common_services.staples, id = "1234" ) )
# Test
cs = CommonServices()
x = dip.Factory( cs.staples, "x" )
cs.staples( id = "y" )
ags = AgentServices( common_services = cs )
ags.shopping_cart() # <-- Fails here