Skip to content

Conversation

@JeevenDhanoa
Copy link

@JeevenDhanoa JeevenDhanoa commented Jul 23, 2021

What does this PR do?

This PR restructures the code in app/data/__init__.py to implement an aggregate pattern. In this example, the DataSources class is the aggregate's root, while the three location service classes form the aggregate's boundary, stored in the
__DATA_SOURCES_MAP dictionary. I made these changes by adding this DataSources class in app/data/__init__.py, making the data sources dictionary private to that class, and updated references to this dictionary and it's accessor method in both app/main.py and app/routers/v2.py. I updated the existing accessor method, and added a new one to accommodate code in v2.py which required access to the entire dictionary. By doing this, the location services are no longer publicly accessible through the data sources dictionary, and the bounds of the aggregate pattern are maintained.

Why make these changes?

Since multiple parts of the code (main, routers/v2) all need access to the different location services, it seems intuitive to group these services up through an aggregate pattern, where the new DataSources class is the publicly visible root that can access all of them. Creating an aggregate and using it in this way helps maintain the constraint that only one location service will be used at any given time, since the primary accessor method of the aggregate root will only return a single location service. I chose the name of DataSources for the aggregate root because it is representative of the aggregate itself, which maintains a dictionary of location services in its boundary which serve as data sources for the API.

@JeevenDhanoa JeevenDhanoa marked this pull request as ready for review July 23, 2021 20:43
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

Successfully merging this pull request may close these issues.

2 participants