Reader small image

You're reading from  Software Architecture with C# 12 and .NET 8 - Fourth Edition

Product typeBook
Published inFeb 2024
PublisherPackt
ISBN-139781805127659
Edition4th Edition
Right arrow
Authors (2):
Gabriel Baptista
Gabriel Baptista
author image
Gabriel Baptista

Gabriel Baptista has been working with software development since the beginning of .NET. Today, his main contributions are managing numerous projects for retail and industry. He is an Azure Platform-as-a-Service (PaaS) solution specialist, teaches at Computing Engineering universities, and helps tech startups as a mentor.
Read more about Gabriel Baptista

Francesco Abbruzzese
Francesco Abbruzzese
author image
Francesco Abbruzzese

Francesco Abbruzzese dedicates his life to his two great passions: software and powerlifting. He is the author of the MVC Controls Toolkit and the Blazor Controls Toolkit libraries. He has contributed to the diffusion and evangelization of the Microsoft web stack since the first version of ASP.NET. His company, Mvcct Team, offers web applications, tools, and services for web technologies. He has moved from AI systems, where he implemented one of the first decision support systems for financial institutions, to top-10 video game titles such as Puma Street Soccer.
Read more about Francesco Abbruzzese

View More author details
Right arrow

Case Study

As mentioned during the previous chapters, for this new edition, we reformulated the way we present the case study of the book – World Wild Travel Club (WWTravelClub). This case study will take you through the process of creating the software architecture for a travel agency.

The purpose of this case study is not to furnish a production-ready application, but just to help you understand the theory explained in each chapter and to provide an example of how to develop an enterprise application with Azure, Azure DevOps, C# 12, .NET 8, ASP.NET Core, and all other technologies introduced in this book.

Let’s start with a description of what our case study application is. Then, we will gradually move to formal specifications.

Introducing World Wild Travel Club

WWTravelClub is a travel agency that was created to revolutionize vacation planning and travel experiences globally. To do so, they are developing an online service, where each aspect of a trip is meticulously curated and supported by a dedicated team of destination-specific experts.

The concept of this platform is that you can be both a visitor and a destination expert at the same time. The more you participate as an expert in a destination, the more points you score. These points can then be redeemed for tickets that people buy online using the platform.

The responsible for the WWTravelClub project came with the following requirements list for the platform:

  • Common user view:
    • Promotional packages on the home page
    • Get a recommendation
    • Search for packages
    • Details for each package:
      • Buy a package
      • Buy a package with a club of experts included
      • Comment...

User needs and system requirements

As presented in Chapter 1, Understanding the Importance of Software Architecture, to summarize the user needs, you may use the User Story pattern. We have used this approach here so that you can read the following user stories for WWTravelClub:

  • US_001: As a common user, I want to view promotional packages on the home page so that I can easily find my next vacation.
  • US_002: As a common user, I want to search for packages I cannot find on the home page so that I can explore other trip opportunities.
  • US_003: As a common user, I want to see the details of a package so that I can decide which package to buy.
  • US_004: As a common user, I want to register myself so that I can start buying the package.
  • US_005: As a registered user, I want to process the payment so that I can buy a package.
  • US_006: As a registered user, I want to buy a package with an expert recommendation included so that I can have an exclusive trip...

Main types of .NET projects used at WWTravelClub

The development of this book’s use case will be based on various kinds of .NET Core Visual Studio projects. This section describes all of them. Let us select New project in the Visual Studio File menu.

For instance, you can filter .NET Core project types by typing them into the search engine as follows:

Figure 21.1: Searching types of .NET Core projects in Visual Studio

There, you will find common C# projects (console, a class library, Windows Forms, and WPF), and various types of test projects, each based on a different test framework: xUnit, NUnit, and MSTest. Choosing among the various testing frameworks is just a matter of preference since they all offer comparable features. Adding tests to each piece of software that composes a solution is a common practice and allows the software to be modified frequently without jeopardizing its reliability.

You may also want to define your class library projects under...

Managing WWTravelClub’s requirements using Azure DevOps

As discussed in Chapter 3, Managing Requirements, an important step for a software development project is where and how the team will organize the user stories mapped from the user needs. There, as described in the Managing system requirements in Azure DevOps section, Azure DevOps enables you to document system requirements using work items, which are mainly tasks or actions that need to be completed to deliver a product or service.

It is also important to remember that the work items available depend on the work item process you select while creating the Azure DevOps project.

Considering the scenario described for WWTravelClub, we decided to use the Agile process and have defined three Epic work items as follows:

Figure 21.2: User case Epics

The creation of these work items is quite simple:

  1. Inside each work item, we link the different types of work items, as you can see in Figure 21.3.
  2. ...

Code standard for WWTravelClub – Dos and don’ts when writing code

In Chapter 4, Best Practices in Coding C# 12, we learned that, as a software architect, you must define a code standard that matches the needs of the company you are working for.

In the sample project of this book, this is no different. The way we decided to present the standard for it is by describing a list of dos and don’ts. We have followed this list while writing the samples we produced. It is worth mentioning that the list is a good way to start your standard and, as a software architect, you should discuss this list with the developers you have in the team so that you can develop it in a practical and good manner.

It is also important to remember that, in the Understanding and applying tools that can evaluate C# code section of Chapter 4, Best Practices in Coding C#12, we have discussed some good tools that can help you define a coding style for your team.

In addition, the statements...

Applying SonarCloud to WWTravelClub APIs

Now that we have already created the WWTravelClub repository, we can Improve the code quality, as discussed in Chapter 4, Best Practices in Coding C# 12. As we saw in that chapter, Azure DevOps enables continuous integration, and this can be useful. In this section, we will discuss more reasons why the DevOps concept and the Azure DevOps platform are so useful.

For now, the only thing we would like to introduce is the possibility of analyzing code after it is committed by the developers but before it has been published. Nowadays, in a SaaS world for application life cycle tools, this is only possible because of some of the SaaS code analysis platforms that we have. This use case will use SonarCloud.

SonarCloud is the SaaS version provided by Sonar. Also, it might be worth noting that SonarCloud is exceptionally easy to self-host; this way, sensitive security information may be kept within an enterprise. It is free for open-source code...

Reusing code as a fast way to deliver good and safe software

As we checked in Chapter 5, Implementing Code Reusability in C# 12, a good approach for accelerating the delivery of good software is creating reusable components. The final design of the solution for evaluating content for WWTravelClub can be checked in the diagram below. This approach consists of using many topics that were discussed in that chapter. First, all the code is placed in a .NET 8 class library. This means that you can add this code to different types of solutions, such as ASP.NET Core web apps and Xamarin apps for the Android and iOS platforms:

Diagrama  Descrição gerada automaticamente

Figure 21.11: WWTravelClub reuse approach

This design makes use of object-oriented principles such as inheritance, so you do not need to write properties and methods more than once that can be used in many classes. The design also makes use of the polymorphism principle so that you can change the behavior of the code without changing the name of the method...

Understanding the domains of the WWTravelClub application

In this section we will perform the DDD analysis of the WWTravelClub system, trying to identify all its domains (also called bounded contexts), that is, the subsystems characterized by different languages used by the experts. Once identified, each domain might be assigned to a different development team and will give rise to a different microservice.

From the requirements listed in the Introducing World Wild Travel Club and User needs and system requirements sections, we know that the WWTravelClub system is composed of the following parts:

  • Information about the available destinations and packages.
  • Reservation/purchase orders subsystem.
  • Communication with the experts/review subsystem.
  • Payment subsystem. We briefly analyzed the features of this subsystem and its relationship with the reservation purchase subsystem at the beginning of Chapter 7, in the Understanding DDD section.
  • User accounts...

The WWTravelClub DevOps approach

During Chapter 8, Understanding DevOps Principles and CI/CD, screenshots from the WWTravelClub project showed the steps needed to implement a good DevOps cycle. The WWTravelClub team has decided to use Azure DevOps because they understand that the tool is essential for getting the best DevOps experience for the whole cycle. In fact, it appears the most complete of the tools offered by GitHub, since it covers the whole CI/CD cycle from requirements collection to deployment in staging and production. Moreover, all team members already know it very well.

The requirements were written using user stories, which can be found in the Work items section of Azure DevOps. The code is placed in the repository of the Azure DevOps project. Both concepts were explained in Chapter 3, Managing Requirements.

The management life cycle used for getting things done is Scrum, presented in Chapter 1, Understanding the Importance of Software Architecture. This approach...

How to choose your data storage in the cloud

In Chapter 12, Choosing Your Data Storage in the Cloud, we learned how to use NoSQL. Now we must decide whether NoSQL databases are adequate for our book use case WWTravelClub application. We need to store the following families of data:

  • Information about available destinations and packages: Relevant operations for these data are reads since packages and destinations do not change very often. However, they must be accessed as fast as possible from all over the world to ensure a pleasant user experience when users browse the available options. Therefore, a distributed relational database with geographically distributed replicas is possible but not necessary since packages can be stored inside their destinations in a cheaper NoSQL database.
  • Destination reviews: In this case, distributed write operations have a non-negligible impact. Moreover, most writes are additions since reviews are not usually updated. Additions benefit...

A worker microservice with ASP.NET Core

In this section, we will show you how to implement a microservice that receives communications through gRPC and an internal queue based on a database table. The first subsection briefly describes the microservice specifications and the overall architecture. You are encouraged to review Chapter 14, Implementing Microservices with .NET, which contains all the theory behind this example.

The specifications and architecture

Our example microservice is required to compute the daily sums of all purchases. According to the data-driven approach, we suppose that all daily sums are pre-computed by receiving messages that are sent as soon as a new purchase is finalized. The purpose of the microservice is to maintain a database of all purchases and all daily sums that can be queried by an administrative user. We will implement just the functionalities needed to fill the two database tables.

The implementation described in this section is based...

A worker microservice based on RabbitMQ

This section explains the modifications needed to use a message broker instead of gRPC communication with an internal queue. This kind of solution is usually more difficult to test and design but allows for better horizontal scaling, and also enables extra features at almost no cost since they are offered by the message broker itself.

We assume that RabbitMQ has already been installed and adequately prepared, as explained in the Installing RabbitMQ core subsection of Chapter 14, Implementing Microservices with .NET.

First, the ASP.NET Core project must be replaced by another Worker Service project. Also, this project must add the connection string to its configuration file and must call the AddStorage extension method to add all the database services to the dependency injection engine. Below is the full content of the Program.cs file:

using GrpcMicroService.HostedServices;
using GrpcMicroServiceStore;
IHost host = Host.CreateDefaultBuilder...

Exposing WWTravelClub packages using Web APIs

In this section, we will implement an ASP.NET REST service that lists all the packages that are available for a given vacation’s start and end dates. For didactic purposes, we will not structure the application according to the best practices we have described previously; instead, we will simply generate the results with a LINQ query that will be directly placed in the controller action method. A well-structured ASP.NET Core application has been presented in Chapter 18, Implementing Frontend Microservices with ASP.NET Core.

Let us make a copy of the WWTravelClubDB solution folder and rename the new folder WWTravelClubWebAPI80. The WWTravelClubDB project was built step by step in the various sections of Chapter 13, Interacting with Data in C# – Entity Framework Core. Let us open the new solution and add a new ASP.NET Core API project to it named WWTravelClubWebAPI80 (the same name as the new solution folder). For simplicity...

Implementing Azure Functions to send emails

Here, we will use a subset of the Azure components. The use case from WWTravelClub proposes a worldwide implementation of the service, and there is a chance that this service will need different architecture designs to achieve all the key performance points that we described in Chapter 1, Understanding the Importance of Software Architecture.

If you go back to the user stories that were described in this chapter, you will find that many needs are related to communication. Because of this, it is common to have some alerts provided by emails in the solution. This implementation will focus on how to send emails. The architecture will be totally serverless. The benefits of using an architecture like that are explained below.

The following diagram shows the basic structure of the architecture. To give users a great experience, all the emails that are sent by the application will be queued asynchronously, thereby preventing significant...

A frontend microservice

In this section, as an example of an ASP.NET Core MVC frontend microservice described in Chapter 18, Implementing Frontend Microservices with ASP.NET Core, we will implement the administrative panel for managing the destinations and packages of the WWTravelClub book use case. The application will be implemented with the DDD approach and associated patterns described in Chapter 7, Understanding the Different Domains in Software Solutions. So, having a good understanding of that chapter is a fundamental prerequisite to reading this chapter. The subsections that follow describe the overall application specifications and organization. The full code of the example can be found in the ch19 folder of the GitHub repository associated with the book.

As usual, let’s start by stating clearly our frontend microservice specifications.

Defining application specifications

The destinations and packages were described in Chapter 13, Interacting with Data...

Using client technologies

In this section, we will implement a package search application for the WWTravelClub book use case. The first subsection explains how to set up the solution exploiting the domain layer and data layer of the MVC application we implemented in the previous section of this chapter.

Preparing the solution

We will modify the PackagesManagement project both to save coding time and to show how to transform a solution based on server-side MVC technology into a solution based on the Blazor client-side technology.

First of all, create a copy of the PackagesManagement solution folder we created in the previous section and rename it PackagesManagementBlazor.

To open the solution, right-click on the web project (the one named PackagesManagement) and remove it (the Remove menu item). Then, go to the solution folder and delete the whole web project folder (the one named PackagesManagement).

Now, right-click on the solution and select Add New Project...

Testing the WWTravelClub application

In this section, we add some unit and functional test projects to the PackagesManagement frontend microservice we described in the A frontend microservice section of this chapter. If you don’t have it, you can download it from the section of the GitHub repository associated with the book in the ch19 folder. It is worth pointing out that in real-world projects, unit test batteries are enhanced by integration tests, and acceptance tests would include not only functional tests but also various kinds of performance tests.

You are encouraged to review Chapter 9, Testing Your Enterprise Application, before continuing with this section.

As a first step, let’s make a new copy of the solution folder and name it PackagesManagementWithTests. Then, open the solution and add it to an xUnit .NET C# test project named PackagesManagementTest. Finally, add a reference to the ASP.NET Core project (PackagesManagement), since we will test it...

Before you begin: join our book community on Discord

Give your feedback straight to the authors themselves and chat to other early readers on our Discord server (find the "software-architecture-csharp-12-dotnet-8" channel under EARLY ACCESS SUBSCRIPTION).

https://packt.link/EarlyAccess

Qr code Description automatically generated

In this chapter, you will learn how to implement presentation layers based on client technologies. While applications based on server technologies run completely on the server and leaves to the browser just the task of rendering the HTM created by the server, applications based on client technologies run almost completely on the client machine and exchange data with the server by calling Web API. In turn, application based on client technologies can be classified as single page applications, which benefit of Web standards, or as native applications, which are tied to specific operating systems and take advantages of specific device peculiarities.Single page applications are based on JavaScript...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Software Architecture with C# 12 and .NET 8 - Fourth Edition
Published in: Feb 2024Publisher: PacktISBN-13: 9781805127659
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Authors (2)

author image
Gabriel Baptista

Gabriel Baptista has been working with software development since the beginning of .NET. Today, his main contributions are managing numerous projects for retail and industry. He is an Azure Platform-as-a-Service (PaaS) solution specialist, teaches at Computing Engineering universities, and helps tech startups as a mentor.
Read more about Gabriel Baptista

author image
Francesco Abbruzzese

Francesco Abbruzzese dedicates his life to his two great passions: software and powerlifting. He is the author of the MVC Controls Toolkit and the Blazor Controls Toolkit libraries. He has contributed to the diffusion and evangelization of the Microsoft web stack since the first version of ASP.NET. His company, Mvcct Team, offers web applications, tools, and services for web technologies. He has moved from AI systems, where he implemented one of the first decision support systems for financial institutions, to top-10 video game titles such as Puma Street Soccer.
Read more about Francesco Abbruzzese