The purpose of this code repository is to provide details about integration of OpenAQ API end-points using ASP.NET Core.
Table of Contents
The OpenAQ Air application is an ASP.NET CORE MVC based web application and it will do the integration with the OpenAQ Air REST API to get the air quality data.
In this application, user's can get the air quality details based on City or Country. 
Solution consists of following core components:
- ASP.NET Core MVC Web Application
- OpenAQ Air REST API
This application is integratied with below applications/systems:
The diagram below showing the overall application architecture in terms of layers and their components.
In this application, Clean Architecture being used used, this patterns always focus on the loosely coupled implementation of the application layers and the same rule applied into the application implementation.
The Domain and Application layers always lie in the design center. These two layers are known as the Core System.
The core layer should not be dependent on any data access layers or any other infrastructure.
We have used the interfaces within the Core layer, which are usually implemented by layers outside the Core. For example, we we want to implement Repository design patterns, we can add an interface e.g. ICityRepository within the Core and its implementation within the infrastructure layer e.g. CityRepository. 
The best practice is that, all the dependencies flows must be inward towards Core Layer, and Core Layer does not have any dependency on any other layer. Of course, infrastructure and Presentation layers must depend on the Core. But both of them do not need to rely on each other.
In this application, i have divided 'Application Core' (from Clean Architecture) into two separate projects like 'Domain' and 'Application'. So 'Domain' project mostly contains 'Entites'(table entities) then 'Application' project contains 'DTO's', 'Interfaces', 'BusinessLogics',etc. So the 'Application' project depends on the 'Domain'. So 'Domain' project can be sharable with other projects as well since it is the parent of layers. 
You can find more details about
Clean Architecturein detailed section.
The Dependency Inversion Principle is one of the SOLID Principles of Object-Oriented class design.
This principle is about dependencies among components. The definition of DIP is given by Robert C. Martin is as follows:
- High-level modules should not depend on low-level modules. Both should depend on abstractions.
- Abstractions should not depend on details. Details should depend on abstractions.

The principle says that high-level modules should depend on abstraction, not on the details, of low-level modules. In simple words, the principle says that there should not be a tight coupling among components of software and to avoid that, the components should depend on abstraction.
The terms Dependency Injection (DI) and Inversion of Control (IoC) are generally used as interchangeably to express the same design pattern.
Inversion of Control (IoC) is a technique to implement the Dependency Inversion Principle in C#. Inversion of control can be implemented using either an abstract class or interface.
The Repository Design Pattern in mediates between the domain and the data mapping layers using a collection-like interface for accessing the domain objects.
In other words, we can say that a Repository Design Pattern acts as a middleman or middle layer between the rest of the application and the data access logic.
That means a repository pattern isolates all the data access code from the rest of the application. The advantage of doing so is that, if you need to do any changes then you need to do it in one place.
Another benefit is that testing your controllers becomes easy because the testing framework need not run against the actual database access code. With repository design pattern, the previous diagram will change to the following diagram: 
Domain Driven Design, first introduced by Eric Evans in 2003, is a software design strategy intended to take complex domains (real-world problems) and simplify them into a extensible and maintainable software solution.
DDD focuses on three core principles:
- Focus on the core domain and domain logic.
- Base complex designs on models of the domain.
- Collaboration with domain experts to improve the application model and resolve any emerging domain-related issues.
- Aggregate Pattern
- Anemic Model
- Anti-Corruption Layer
- Entity
- Repository Pattern
- Specification Pattern
- Ubiquitous Language
- Value Object
In this application required configuration managed from OpenAQAir.Web/appsettings.json file:
In this application we are using In-Memory cache and following format being used to create the Cache Key:
items-{0}-{1}-{2}-{3}-{4}-{5}
The duration of the cache key is 5 minutes and mentioned at CacheHelpers.cs.
To make above values dynamic, we can move these values to OpenAQAir.Web/appsettings.json file.
In this application we are using Serilog which provides diagnostic logging to files.
The Serilog configuration managed via OpenAQAir.Web/appsettings.json file
You can check the section Application Configurations for more details.
Please find below list of interation with the application:
OpenAQ is a non-profit organization empowering communities around the globe to clean their air by harmonizing, sharing, and using open air quality data.
OpenAQ provides the REST API to access the air quality data.
In this applicaiton, we are using Country and City end-points to get the air quality related data over the HTTPS.
As explained above, this application uses the OpenAQ Air REST API and provides following functionalities based on this:
User can get the air quality details of Single or Multiple cities separated by comma (',').
You can get the city details after entering the city name where the first character of each word should be in capital letter, e.g. Lucknow, etc..
If you enter the city name like this lucknow, then you would not get any result.
You can get multiple cities details separate it by a comma (',').
Where the first character of each word should be in capital letter, e.g. Lucknow, etc..
If you enter the city name like this lucknow, then you would not get any result. 
This option will use the OpenAQ Air cities API to get the air quality of cities. 
User can get the air quality details of Single or Multiple countries separated by comma (',').
You can get all the country details if you leave blank the country text box.
You can get multiple countries details separate it by a comma (',').
You have to provide the two letter country code as described in the ISO 3166 international standard, e.g. IN, GB etc..
The country code are case-insensitive.
This option will use the OpenAQ Air Country API to get the air quality of countries.
If you will
notselect theSort Orderthen by defaultAscending Orderwould be applied.
Applications that follow the Dependency Inversion Principle as well as the Domain-Driven Design (DDD) principles tend to arrive at a similar architecture.
This architecture has gone by many names over the years. One of the first names was Hexagonal Architecture, followed by Ports-and-Adapters. More recently, it's been cited as the Onion Architecture or Clean Architecture. The latter name, Clean Architecture, is used now mostly.
The guiding principle of this architecture is the Dependency Inversion Principle, part of the SOLID principles of object-oriented design.
This principles states that:
High level modules should not depend on low level modules, but instead both should depend on abstractions.High level modules are things like business rules and domain models.Low level modules are closer to out-of-process communication, such as through the user interface or communicating with services or the file system.
The main Clean Architecture diagram as presented by Robert Martin:
- The Clean Architecture
- Domain-Driven Design: What is it and how do you use it?
- S.O.L.I.D. Principles of Object-Oriented Programming in C#
- Domain Driven Design
- What is Clean Architecture
- Clean Architecture for ASP.NET Core Solution: A Case Study
- Clean Architecture with .NET Core: Getting Started
- Clean Architecture .NET Core (Part 2: Implementation)
- Domain Driven Design
- Top icons created by Vectors Market - Flaticon
- Clean Architecture with ASP.Net Core
- Jason Taylor’s talk at NDC Sydney (2019)










