Skip to content

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

4 participants