12 Using IAsyncEnumerable<T> and yield return

 

This chapter covers

  • Using the generic Queue data structure
  • Using yield return and IAsyncEnumerable<T>
  • Creating views
  • Using private getters and setters with auto-properties
  • How structs differ from classes
  • Using checked and unchecked keywords

In the previous chapters, we examined the codebase we inherited and noted where we could make improvements. Then, we partially implemented our version of the codebase, adhering to FlyTomorrow’s OpenAPI specification. In chapters 10 and 11, we implemented the BookingService class and decided that there was no need for a CustomerService class. Figure 12.1 shows where we are in the scheme of the book.

Figure 12.1 In this chapter, we wrap up the services layer by implementing the AirportService and FlightService classes. By implementing those classes, we finish the service layer rewrite of the Flying Dutchman Airlines service.

If we look at which classes we need to implement to complete our service layer, an encouraging picture follows:

  • CustomerService (chapter 10)
  • BookingService (chapters 10 and 11)
  • AirportService (this chapter)
  • FlightService (this chapter)

We are halfway done with the service layer classes. In this chapter, we’ll wrap up the service layer implementation by writing code for the AirportService and FlightService classes. After this chapter, we are in an excellent spot to move on to our last architectural layer: the controller layer.

12.1 Do we need an AirportService class?

12.2 Implementing the FlightService class

12.2.1 Getting information on a specific flight from the FlightRepository

12.2.2 Combining two data streams into a view

12.2.3 Using the yield return keywords with try-catch code blocks