python-dependency-injector/examples/miniapps/services/main.py

19 lines
517 B
Python
Raw Normal View History

"""Dependency Injector @inject decorator example."""
2016-04-20 14:19:54 +03:00
2016-06-03 17:35:55 +03:00
from dependency_injector.injections import inject
from containers import Services
2016-04-20 14:19:54 +03:00
2016-06-03 17:35:55 +03:00
@inject(users_service=Services.users)
@inject(auth_service=Services.auth)
@inject(photos_service=Services.photos)
def main(users_service, auth_service, photos_service):
2016-04-20 14:19:54 +03:00
"""Main function."""
user = users_service.get_user('user')
auth_service.authenticate(user, 'secret')
photos_service.upload_photo(user['id'], 'photo.jpg')
2016-04-20 14:19:54 +03:00
if __name__ == '__main__':
main()