-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update dependencies section add real world example of dependenc…
…y injection with Factory
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from esmerald import Factory, Include, Inject | ||
|
||
route_patterns = [ | ||
Include( | ||
"/api/v1", | ||
routes=[ | ||
Include("/accounts", namespace="accounts.v1.urls"), | ||
Include("/articles", namespace="articles.v1.urls"), | ||
Include("/posts", namespace="posts.v1.urls"), | ||
], | ||
interceptors=[LoggingInterceptor], # Custom interceptor | ||
dependencies={ | ||
"user_dao": Inject(lambda: UserDAO()), | ||
"article_dao": Inject(lambda: ArticleDAO()), | ||
"post_dao": Inject(lambda: PostDAO()), | ||
}, | ||
) | ||
] | ||
|
||
|
||
route_patterns = [ | ||
Include( | ||
"/api/v1", | ||
routes=[ | ||
Include("/accounts", namespace="accounts.v1.urls"), | ||
Include("/articles", namespace="articles.v1.urls"), | ||
Include("/posts", namespace="posts.v1.urls"), | ||
], | ||
interceptors=[LoggingInterceptor], # Custom interceptor | ||
dependencies={ | ||
"user_dao": Inject(Factory(UserDAO)), | ||
"article_dao": Inject(Factory(ArticleDAO)), | ||
"post_dao": Inject(Factory(PostDAO)), | ||
}, | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import List | ||
|
||
from esmerald import get | ||
from esmerald.openapi.datastructures import OpenAPIResponse | ||
|
||
|
||
@get( | ||
"/users", | ||
tags=["User"], | ||
description="List of all the users in the system", | ||
summary="Lists all users", | ||
responses={ | ||
200: OpenAPIResponse(model=[UserOut]), | ||
400: OpenAPIResponse(model=Error, description="Bad response"), | ||
}, | ||
) | ||
async def users(user_dao: UserDAO) -> List[UserOut]: | ||
""" | ||
Lists all the users in the system. | ||
""" | ||
return await user_dao.get_all() |