Skip to content

providers.Object not injecting the original object #231

@davidcim

Description

@davidcim

In the documentation you can read about the Object provider:

Object - provider that returns provided instance "as is".

However when I try to inject a parameter from an Object provider I get a different instance. I have been only able to get the original object using a Callable provider.

This code exemplifies the issue:

from dependency_injector import containers, providers


class Obj:
    pass


my_obj = Obj()


class IocContainer(containers.DeclarativeContainer):

    obj1 = providers.Object(
        my_obj,
    )

    obj2 = providers.Callable(
        lambda: my_obj
    )


ioc = IocContainer()
print('Original object: ', my_obj)
print('providers.Object', ioc.obj1())
print('providers.Callable', ioc.obj2())

As you can see in the output, providers.Object is returning a different instance:

Original object:  <__main__.Obj object at 0x7fcc0d1e16a0>
providers.Object <__main__.Obj object at 0x7fcc0d1e17f0>
providers.Callable <__main__.Obj object at 0x7fcc0d1e16a0>

I am using Python 3.5.2 and dependency-injector 3.14.10

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions