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

feature request: provider for "self" #364

Closed
shaunc opened this issue Jan 19, 2021 · 9 comments
Closed

feature request: provider for "self" #364

shaunc opened this issue Jan 19, 2021 · 9 comments
Assignees
Labels

Comments

@shaunc
Copy link

shaunc commented Jan 19, 2021

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)?

@rmk135
Copy link
Member

rmk135 commented Jan 19, 2021

Hey @shaunc , caught it.

@rmk135
Copy link
Member

rmk135 commented Feb 6, 2021

I'm working on this feature now. Already have prototype. Plan to release by Monday.

@rmk135 rmk135 removed the question label Feb 6, 2021
@rmk135 rmk135 changed the title question / feature request: provider for "self" feature request: provider for "self" Feb 6, 2021
@shaunc
Copy link
Author

shaunc commented Feb 6, 2021

Great -- thanks!

@rmk135
Copy link
Member

rmk135 commented Feb 7, 2021

@rmk135
Copy link
Member

rmk135 commented Feb 8, 2021

@shaunc Closing this issue. Let me know if you have any questions.

@rmk135 rmk135 closed this as completed Feb 8, 2021
@shaunc
Copy link
Author

shaunc commented Feb 8, 2021

Just a small doc comment/suggestion -- if I didn't know about this feature, I might search for it in "providers." Having the main doc page under containers is fine, but maybe have a link to it on the main "providers" page?

@rmk135
Copy link
Member

rmk135 commented Feb 9, 2021

Hm, that's a good idea, you're right. I think I'll just move it under "Providers."

@rmk135
Copy link
Member

rmk135 commented Feb 9, 2021

@rmk135
Copy link
Member

rmk135 commented Feb 9, 2021

Thanks @shaunc

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

No branches or pull requests

2 participants