2020-09-07 04:51:38 +03:00
|
|
|
"""Main module."""
|
|
|
|
|
2020-10-09 22:16:27 +03:00
|
|
|
import sys
|
2020-09-07 04:51:38 +03:00
|
|
|
|
2020-11-16 00:06:42 +03:00
|
|
|
from dependency_injector.wiring import inject, Provide
|
2020-09-07 04:51:38 +03:00
|
|
|
|
2020-10-09 22:16:27 +03:00
|
|
|
from .user.repositories import UserRepository
|
|
|
|
from .photo.repositories import PhotoRepository
|
|
|
|
from .analytics.services import AggregationService
|
|
|
|
from .containers import ApplicationContainer
|
2020-09-07 04:51:38 +03:00
|
|
|
|
|
|
|
|
2020-11-16 00:06:42 +03:00
|
|
|
@inject
|
2020-10-09 22:16:27 +03:00
|
|
|
def main(
|
|
|
|
user_repository: UserRepository = Provide[
|
|
|
|
ApplicationContainer.user_package.user_repository
|
|
|
|
],
|
|
|
|
photo_repository: PhotoRepository = Provide[
|
|
|
|
ApplicationContainer.photo_package.photo_repository
|
|
|
|
],
|
|
|
|
aggregation_service: AggregationService = Provide[
|
|
|
|
ApplicationContainer.analytics_package.aggregation_service
|
|
|
|
],
|
|
|
|
) -> None:
|
2020-09-07 04:51:38 +03:00
|
|
|
user1 = user_repository.get(id=1)
|
|
|
|
user1_photos = photo_repository.get_photos(user1.id)
|
|
|
|
print(f'Retrieve user id={user1.id}, photos count={len(user1_photos)}')
|
|
|
|
|
|
|
|
user2 = user_repository.get(id=2)
|
|
|
|
user2_photos = photo_repository.get_photos(user2.id)
|
|
|
|
print(f'Retrieve user id={user2.id}, photos count={len(user2_photos)}')
|
|
|
|
|
|
|
|
assert aggregation_service.user_repository is user_repository
|
|
|
|
assert aggregation_service.photo_repository is photo_repository
|
|
|
|
print('Aggregate analytics from user and photo packages')
|
2020-09-07 19:03:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-10-09 22:16:27 +03:00
|
|
|
application = ApplicationContainer()
|
|
|
|
application.config.from_ini('config.ini')
|
|
|
|
application.wire(modules=[sys.modules[__name__]])
|
|
|
|
|
2020-09-07 19:03:49 +03:00
|
|
|
main()
|