Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Another puzzling issue #200
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
added a commit
Jul 26, 2018
Hi @j4zzcat ,
Mostly the same reason as it was at #198 , but now in different place. I call what you do here "chained providers" (
Fixed in 3.12.4.