Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another puzzling issue #200

j4zzcat opened this issue Jul 25, 2018 · 3 comments

Another puzzling issue #200

j4zzcat opened this issue Jul 25, 2018 · 3 comments


Copy link

j4zzcat commented Jul 25, 2018

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(, id = "1234" ) )

# Test
cs = CommonServices()
x  = dip.Factory(, "x" ) id = "y" )

ags = AgentServices( common_services = cs )

ags.shopping_cart() # <-- Fails here
@rmk135 rmk135 self-assigned this Jul 26, 2018
rmk135 added a commit that referenced this issue Jul 26, 2018
Copy link

rmk135 commented 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" (providers.Factory(providers.Callable(...))), but, frankly speaking, I haven't paid to much attention to it yet, so some things could be buggy. Sorry about that.

Fixed in 3.12.4.


@rmk135 rmk135 added the bug label Jul 26, 2018
@rmk135 rmk135 closed this as completed Jul 26, 2018
Copy link

j4zzcat commented Jul 26, 2018

Thank you @rmk135 for the super-quick response!

Copy link

rmk135 commented Jul 26, 2018

You're welcome :) Thanks for posting the issue - it really helps to make Dependency Injector better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants