Skip to content

Alias providers using Delegate and DependenciesContainer #937

@gael-ft

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions