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

Add manage_scope in wrap_injecton and use it for celery integration #388

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

ApostolFet
Copy link
Contributor

Scope control within the wrap_injecton will make it easier to add integrations, as well as fix the current celery integration issue: #385

Example usage:

def inject(func: Callable[P, T]) -> Callable[P, T]:
    return wrap_injection(
        func=func,
        is_async=False,
        container_getter=lambda args, kwargs: current_app.conf[
            CONTAINER_NAME
        ],
        manage_scope=True,
    )

In container_getter we get container with scope APP and create wrapper, which enter in scope Request and exit after function call.

dependencies: dict[str, DependencyKey],
func: Callable[P, Awaitable[T]],
*,
manage_scope: bool = False,
) -> Callable[P, Awaitable[T]]:
if isasyncgenfunction(func):
Copy link
Member

@Tishka17 Tishka17 Mar 10, 2025

Choose a reason for hiding this comment

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

Looks like its time to introduce some kine of dispatch dict:

{
    Target(type_=AsyncGenerator, manage_scope=True): _get_auto_injected_async_gen_scoped,
    Target(type_=AsyncFunc, manage_scope=True): _get_auto_injected_async_func_scoped,
}

Or even code gen =D

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.

2 participants