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

Dependency alias #6

Closed
Tishka17 opened this issue Jan 21, 2024 · 0 comments
Closed

Dependency alias #6

Tishka17 opened this issue Jan 21, 2024 · 0 comments

Comments

@Tishka17
Copy link
Member

Tishka17 commented Jan 21, 2024

Sometimes (especially when we follow interface segregation principle) we have single implementation for multiple dependencies. It would be useful to have single instance for all of them.

Let's
Current way to make alias:

class MyProvider(Provider):
    @provide(scope=MyScope.REQUEST)
    def get_repo(self, repo: UserRepositoryImpl) -> UserGetter:
       return repo

We can rely on the fact that scope must be the same, so this can be simplified to:

class MyProvider(Provider):
    repo = alias(UserRepositoryImpl, dependency=UserGetter)
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

No branches or pull requests

1 participant