Skip to content

feature request: provider for "self" #364

@shaunc

Description

@shaunc

I would like a provider to be able to pass a container as an argument:

class Container(containers.DeclarativeContainer):

    foo = providers.Callable(calc_foo, containers.MarkerForContainer)
    bar = providers.Object('hello')

container = Container()
container.override_providers(container=container)

def calc_foo(container):
    print(container.bar())

container.foo()  # prints "hello" - ?

I assume that is impossible to do directly, right now? I guess perhaps I could do:

class Container(containers.DeclarativeContainer):

    container = providers.DependenciesContainer()
    foo = providers.Callable(calc_foo, container)
    bar = providers.Object('hello')

container = Container()
container.override_providers(container=container)

def calc_foo(container):
    print(container.bar())

container.foo()  # prints "hello" - ?

But having the container work without having to put cheese in it (to use a mousetrap analogy) would be great... any chance of something like the former (if indeed it isn't possible)?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions