Skip to content

Alias providers using Delegate and DependenciesContainer #937

Description

@gael-ft

My own container depends on an other container that provides a ThreadSafeSingleton.
I would like my own container to provide this singleton as well, like a alias to the singleton.
E.g.

from dependency_injector import containers, providers

# Containers I can't update
class NestedOtherContainer(containers.DeclarativeContainer):
    a_client = providers.ThreadSafeSingleton(...)

class OtherContainer(containers.DeclarativeContainer):
    clients = providers.DependenciesContainer()


# my container
class MyContainer(containers.DeclarativeContainer):
    other_container = providers.DependenciesContainer()
    a_alias = ???

I tried several things using Delegate like

a_alias = providers.Delegate(other_container.clients.a_client)

a_alias = providers.Delegate(other_container.clients.provided.a_client)

# etc.

But none of them works when MyContainer(other_container=...).a_alias(), getting things like AttributeGetter or MethodCaller.

Any idea on how to do this kind of aliasing ?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions