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

Per-request aliases #17

Open
Tishka17 opened this issue Jan 27, 2024 · 1 comment
Open

Per-request aliases #17

Tishka17 opened this issue Jan 27, 2024 · 1 comment
Labels
draft Needs information or coordination with other issues enhancement New feature or request

Comments

@Tishka17
Copy link
Collaborator

Tishka17 commented Jan 27, 2024

Allow to set alias when entering scope. That will allow to change logic for specific route without moving it to container

with container(aliases={A: A1}) as request_container:
   request_container.get(A) # this will reuturn A1

Aliases should be copied to inner scopes if we do not know the scope of depedency. But the do not affect the outer scope.

@Tishka17
Copy link
Collaborator Author

Alternative:

from enum import StrEnum
from typing import Annotated

class ProviderType(StrEnum):
    headers = "HEADERS"
    body = "BODY"

class DIProvider(Provider):
    @provide()
    def get_provider() -> IdProvider:
        ...

    @provide(tags=[ProviderType.headers])
    def get_provider() -> IdProvider:
        ...

@inject(tags=[ProviderType.headers])
def func(
    id_provider: Annotated[IdProvider, Depends()],
):
    ...

@Tishka17 Tishka17 added the enhancement New feature or request label Feb 17, 2024
@Tishka17 Tishka17 added the draft Needs information or coordination with other issues label Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draft Needs information or coordination with other issues enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant