Skip to content
  • Sponsor
  • Notifications You must be signed in to change notification settings
  • Fork 321
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

Fix Closing dependency resolution #711

Closed

Conversation

jazzthief
Copy link
Contributor

@jazzthief jazzthief commented May 22, 2023

Fix issues found when using Closing to implement per-function scope for Resources.

nested_service = providers.Factory(NestedService, factory_service)


class ContainerSingleton(containers.DeclarativeContainer):
Copy link
Contributor Author

@jazzthief jazzthief May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another container to cover a case where a resource is not at the end of the dependency graph. A Singleton provider type is arbitrary - its type doesn't play any role in injections, just needed something for a Resource to depend on.

@jazzthief
Copy link
Contributor Author

I have in mind a few potential test cases that could be added: when there are no resources in the dependency graph; and when there are several different resources.
Apart from that, the change is ready.

@jazzthief jazzthief marked this pull request as ready for review May 24, 2023 13:51
if not isinstance(arg, providers.Provider) or not hasattr(arg, "args"):
continue

if not arg.args and isinstance(arg, providers.Resource):
if isinstance(arg, providers.Resource):
return {str(id(arg)): arg}
Copy link

@mspiridonov2706 mspiridonov2706 Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @jazzthief. Fix not working for several Resources. Maybe something like this?

Suggested change
return {str(id(arg)): arg}
closing_deps |= {str(id(arg)): arg}

@ZipFile
Copy link
Contributor

ZipFile commented Feb 23, 2025

Changes from this PR were merged as part of #852

@ZipFile ZipFile closed this Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants