mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-06-29 18:03:13 +03:00
Refactor multiple container example to use wiring
This commit is contained in:
parent
fdb33ca5ce
commit
609ec5cac8
|
@ -24,6 +24,6 @@ You should see:
|
|||
|
||||
.. code-block:: bash
|
||||
|
||||
[2020-09-04 16:06:00,750] [DEBUG] [example.services.UserService]: User user@example.com has been found in database
|
||||
[2020-09-04 16:06:00,750] [DEBUG] [example.services.AuthService]: User user@example.com has been successfully authenticated
|
||||
[2020-09-04 16:06:00,750] [DEBUG] [example.services.PhotoService]: Photo photo.jpg has been successfully uploaded by user user@example.com
|
||||
[2020-10-06 15:36:55,961] [DEBUG] [example.services.UserService]: User user@example.com has been found in database
|
||||
[2020-10-06 15:36:55,961] [DEBUG] [example.services.AuthService]: User user@example.com has been successfully authenticated
|
||||
[2020-10-06 15:36:55,961] [DEBUG] [example.services.PhotoService]: Photo photo.jpg has been successfully uploaded by user user@example.com
|
||||
|
|
|
@ -2,23 +2,29 @@
|
|||
|
||||
import sys
|
||||
|
||||
from dependency_injector.wiring import Provide
|
||||
|
||||
from .services import UserService, AuthService, PhotoService
|
||||
from .containers import Application
|
||||
|
||||
|
||||
def main(email: str, password: str, photo: str) -> None:
|
||||
application = Application()
|
||||
|
||||
application.config.from_yaml('config.yml')
|
||||
application.core.configure_logging()
|
||||
|
||||
user_service = application.services.user()
|
||||
auth_service = application.services.auth()
|
||||
photo_service = application.services.photo()
|
||||
|
||||
def main(
|
||||
email: str,
|
||||
password: str,
|
||||
photo: str,
|
||||
user_service: UserService = Provide[Application.services.user],
|
||||
auth_service: AuthService = Provide[Application.services.auth],
|
||||
photo_service: PhotoService = Provide[Application.services.photo],
|
||||
):
|
||||
user = user_service.get_user(email)
|
||||
auth_service.authenticate(user, password)
|
||||
photo_service.upload_photo(user, photo)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
application = Application()
|
||||
application.config.from_yaml('config.yml')
|
||||
application.core.configure_logging()
|
||||
application.wire(modules=[sys.modules[__name__]])
|
||||
|
||||
main(*sys.argv[1:])
|
||||
|
|
Loading…
Reference in New Issue
Block a user