Software Architecture with C# 9 and .NET 5: Architecting software solutions using microservices, DevOps, and design patterns for Azure, 2nd Edition

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Design scalable and high-performance enterprise applications using the latest features of C# 9 and .NET 5

Key Features

  • Gain fundamental and comprehensive software architecture knowledge and the skillset to create fully modular apps
  • Design high-performance software systems using the latest features of .NET 5 and C# 9
  • Solve scalability problems in web apps using enterprise architecture patterns

Book Description

Software architecture is the practice of implementing structures and systems that streamline the software development process and improve the quality of an app. This fully revised and expanded second edition, featuring the latest features of .NET 5 and C# 9, enables you to acquire the key skills, knowledge, and best practices required to become an effective software architect.

This second edition features additional explanation of the principles of Software architecture, including new chapters on Azure Service Fabric, Kubernetes, and Blazor. It also includes more discussion on security, microservices, and DevOps, including GitHub deployments for the software development cycle.

You will begin by understanding how to transform user requirements into architectural needs and exploring the differences between functional and non-functional requirements. Next, you will explore how to carefully choose a cloud solution for your infrastructure, along with the factors that will help you manage your app in a cloud-based environment.

Finally, you will discover software design patterns and various software approaches that will allow you to solve common problems faced during development.

By the end of this book, you will be able to build and deliver highly scalable enterprise-ready apps that meet your organization's business requirements.

What you will learn

  • Use different techniques to overcome real-world architectural challenges and solve design consideration issues
  • Apply architectural approaches such as layered architecture, service-oriented architecture (SOA), and microservices
  • Leverage tools such as containers, Docker, Kubernetes, and Blazor to manage microservices effectively
  • Get up to speed with Azure tools and features for delivering global solutions
  • Program and maintain Azure Functions using C# 9 and its latest features
  • Understand when it is best to use test-driven development (TDD) as an approach for software development
  • Write automated functional test cases
  • Get the best of DevOps principles to enable CI/CD environments

Who this book is for

This book is for engineers and senior software developers aspiring to become architects or looking to build enterprise applications with the .NET Stack. Basic familiarity with C# and .NET is required to get the most out of this book.

Table of Contents

  1. Understanding the Importance of Software Architecture
  2. Non-Functional Requirements
  3. Documenting Requirements with Azure DevOps
  4. Deciding the Best Cloud-Based Solution
  5. Applying a Microservice Architecture to Your Enterprise Application
  6. Azure Service Fabric
  7. Azure Kubernetes Service
  8. Interacting with Data in C# – Entity Framework Core
  9. How to Choose Your Data Storage in the Cloud
  10. Working with Azure Functions
  11. Design Patterns and .NET 5 Implementation
  12. Understanding the Different Domains in Software Solutions
  13. Implementing Code Reusability in C# 9
  14. Applying Service-Oriented Architectures with .NET Core
  15. Presenting ASP.NET Core MVC
  16. Blazor WebAssembly
  17. Best Practices in Coding C# 9
  18. Testing Your Code with Unit Test Cases and TDD
  19. (N.B. Please use the Look Inside option to see further chapters)

Author(s): Gabriel Baptista, Francesco Abbruzzese
Edition: 2
Publisher: Packt Publishing
Year: 2020

Language: English
Commentary: True PDF
Pages: 700

Cover
Copyright
Packt Page
Contributors
Table of Contents
Preface
Chapter 1: Understanding the Importance of Software Architecture
What is software architecture?
Creating an Azure account
Software development process models
Reviewing traditional software development process models
Understanding the waterfall model principles
Analyzing the incremental model
Understanding agile software development process models
Lean software development
Extreme Programming
Getting into the Scrum model
Gathering the right information to design high-quality software
Understanding the requirements gathering process
Detecting exact user needs
Analyzing requirements
Writing the specifications
Understanding the principles of scalability, robustness, security, and performance
Reviewing the specification
Using design techniques as a helpful tool
Design Thinking
Design Sprint
Common cases where the requirements gathering process impacted system results
Case 1 – my website is too slow to open that page!
Understanding caching
Applying asynchronous programming
Dealing with object allocation
Getting better database access
Case 2 – the user's needs are not properly implemented
Case 3 – the usability of the system does not meet user needs
Case study – introducing World Wild Travel Club
Understanding user needs and system requirements
Summary
Questions
Further reading
Chapter 2: Non-Functional Requirements
Technical requirements
Enabling scalability, availability, and resiliency with Azure and .NET 5
Creating a scalable web app in Azure
Vertical scaling (Scaling up)
Horizontal scaling (Scaling out)
Creating a scalable web app with .NET 5
Performance issues that need to be considered when programming in C#
String concatenation
Exceptions
Multithreading environments for better results – dos and don'ts
Usability – why inserting data takes too much time
Designing fast selection logic
Selecting from a huge number of items
The fantastic world of interoperability with .NET Core
Creating a service in Linux
Achieving security by design
List of practices for achieving a safe architecture
Authentication
Sensitive data
Web security
Book use case – understanding the main types of .NET Core projects
Summary
Questions
Further reading
Chapter 3: Documenting Requirements with Azure DevOps
Technical requirements
Introducing Azure DevOps
Organizing your work using Azure DevOps
Azure DevOps repository
Package feeds
Test plans
Pipelines
Managing system requirements in Azure DevOps
Epic work items
Feature work items
Product Backlog items/User Story work items
Use case – presenting use cases in Azure DevOps
Summary
Questions
Further reading
Chapter 4: Deciding the Best Cloud-Based Solution
Technical requirements
Different software deployment models
IaaS and Azure opportunities
Security responsibility in IaaS
PaaS – a world of opportunities for developers
Web apps
SQL Databases
Azure Cognitive Services
SaaS – just sign in and get started!
Understanding what serverless means
Why are hybrid applications so useful in many cases?
Book use case – which is the best cloud solution?
Summary
Questions
Further reading
Chapter 5: Applying a Microservice Architecture to Your Enterprise Application
Technical requirements
What are microservices?
Microservices and the evolution of the concept of modules
Microservices design principles
The independence of design choices
Independence from the deployment environment
Loose coupling
No chained requests/responses
Containers and Docker
When do microservices help?
Layered architectures and microservices
The presentation layer
When is it worth considering microservice architectures?
How does .NET deal with microservices?
.NET communication facilities
Resilient task execution
Using generic hosts
Visual Studio support for Docker
Analyzing the Docker file
Publishing the project
Azure and Visual Studio support for microservice orchestration
Which tools are needed to manage microservices?
Defining your private Docker registry in Azure
Summary
Questions
Further reading
Chapter 6: Azure Service Fabric
Technical requirements
Visual Studio support for Azure Service Fabric
Defining and configuring your Azure Service Fabric cluster
Step 1 – Basic information
Step 2 – Cluster configuration
Step 3 – Security configuration
Use case – Logging microservices
Ensuring message idempotency
The Interaction library
Implementing the receiving side of communications
Implementing service logic
Defining the microservice's host
Communicating with the service
Testing the application
Summary
Questions
Further reading
Chapter 7: Azure Kubernetes Service
Technical requirements
Kubernetes basics
.yaml files
ReplicaSets and Deployments
StatefulSets
Services
Ingresses
Interacting with Azure Kubernetes clusters
Using Kubectl
Deploying the demo Guestbook application
Advanced Kubernetes concepts
Requiring permanent storage
Kubernetes secrets
Liveness and readiness checks
Autoscaling
Helm – Installing an Ingress Controller
Summary
Questions
Further reading
Chapter 8: Interacting with Data in C# – Entity Framework Core
Technical requirements
Understanding ORM basics
Configuring Entity Framework Core
Defining DB entities
Defining the mapped collections
Completing the mapping configuration
Entity Framework Core migrations
Understanding stored procedures and direct SQL commands
Querying and updating data with Entity Framework Core
Returning data to the presentation layer
Issuing direct SQL commands
Handling transactions
Deploying your data layer
Understanding Entity Framework Core advanced features
Summary
Questions
Further reading
Chapter 9: How to Choose Your Data Storage in the Cloud
Technical requirements
Understanding the different repositories for different purposes
Relational databases
NoSQL databases
Redis
Azure storage accounts
Choosing between structured or NoSQL storage
Azure Cosmos DB – an opportunity to manage a multi-continental database
Creating an Azure Cosmos DB account
Creating an Azure Cosmos container
Accessing Azure Cosmos data
Defining database consistency
The Cosmos DB client
The Cosmos DB Entity Framework Core provider
Use case – storing data
Implementing the destinations/packages database with Cosmos DB
Summary
Questions
Further reading
Chapter 10: Working with Azure Functions
Technical requirements
Understanding the Azure Functions app
Consumption plan
Premium plan
App Service plan
Programming Azure functions using C#
Listing Azure Functions templates
Maintaining Azure functions
Use case – Implementing Azure Functions to send emails
First step – Creating Azure Queue storage
Second step – Creating the function to send emails
Third step – Creating the queue trigger function
Summary
Questions
Further reading
Chapter 11: Design Patterns and .NET 5 Implementation
Technical requirements
Understanding design patterns and their purpose
Builder pattern
Factory pattern
Singleton pattern
Proxy pattern
Command pattern
Publisher/Subscriber pattern
Dependency Injection pattern
Understanding the available design patterns in .NET 5
Summary
Questions
Further reading
Chapter 12: Understanding the Different Domains in Software Solutions
Technical requirements
What are software domains?
Understanding domain-driven design
Entities and value objects
Using SOLID principles to map your domains
Aggregates
The repository and Unit of Work patterns
DDD entities and Entity Framework Core
Command Query Responsibility Segregation (CQRS) pattern
Command handlers and domain events
Event sourcing
Use case – understanding the domains of the use case
Summary
Questions
Further reading
Chapter 13: Implementing Code Reusability in C# 9
Technical requirements
Understanding the principles of code reusability
What is not code reuse?
What is code reuse?
Reusability in the development life cycle
Using .NET 5 or .NET Standard for code reuse
Creating a .NET Standard library
How does C# deal with code reuse?
Object-oriented analysis
Generics
What if the code is not reusable?
I have my libraries. How do I promote them?
Documenting .NET libraries using DocFX
Documenting a Web API using Swagger
Use case – reusing code as a fast way to deliver good and safe software
Summary
Questions
Further reading
Chapter 14: Applying Service-Oriented Architectures with .NET Core
Technical requirements
Understanding the principles of the SOA approach
SOAP web services
REST web services
Service type compatibility rules
Rest and native HTTP features
Example of methods in the REST language
The OpenAPI standard
REST service authorization and authentication
How does .NET 5 deal with SOA?
SOAP client support
gRPC support
A short introduction to ASP.NET Core
Implementing REST services with ASP.NET Core
ASP.NET Core service authorization
ASP.NET Core support for OpenAPI
.Net Core HTTP clients
Use case – exposing WWTravelClub packages
Summary
Questions
Further reading
Chapter 15: Presenting ASP.NET Core MVC
Technical requirements
Understanding the presentation layers of web applications
Understanding the ASP.NET Core MVC structure
How the ASP.NET Core pipeline works
Loading configuration data and using it with the options framework
Defining the ASP.NET Core MVC pipeline
Defining controllers and ViewModels
Understanding Razor Views
Learning the Razor flow of control statements
Understanding Razor View properties
Using Razor tag helpers
Reusing view code
What is new in the latest versions of ASP.NET Core?
Understanding the connection between ASP.NET Core MVC and design principles
Advantages of the ASP.NET Core pipeline
Server-side and client-side validation
ASP.NET Core globalization
The MVC pattern
Use case – implementing a web app in ASP.NET Core MVC
Defining application specifications
Defining the application architecture
Defining the domain layer
Defining the data layer
Defining the application layer
Controllers and views
Summary
Questions
Further reading
Chapter 16: Blazor WebAssembly
Technical requirements
Blazor WebAssembly architecture
What is a Single-Page Application?
Loading and starting the application
Routing
Blazor pages and components
Component structure
Templates and cascading parameters
Events
Bindings
How Blazor updates HTML
Component lifecycle
Blazor forms and validation
Blazor advanced features
References to components and HTML elements
JavaScript interoperability
Globalization and localization
Authentication and authorization
Communication with the server
Third-party tools for Blazor WebAssembly
Use case – implementing a simple application in Blazor WebAssembly
Preparing the solution
Implementing the required ASP.NET Core REST APIs
Implementing the business logic in a service
Implementing the user interface
Summary
Questions
Further reading
Chapter 17: Best Practices in Coding C# 9
Technical requirements
The more complex your code, the worse a programmer you are
Maintainability index
Cyclomatic complexity
Depth of inheritance
Class coupling
Lines of code
Using a version control system
Dealing with version control systems in teams
Writing safe code in C#
try-catch
try-finally and using
The IDisposable interface
.NET 5 tips and tricks for coding
WWTravelClub – DOs and DON'Ts in writing code
Summary
Questions
Further reading
Chapter 18: Testing Your Code with Unit Test Cases and TDD
Technical requirements
Understanding unit and integration tests
Automating unit and integration tests
Writing automated (unit and integration) tests
Writing acceptance and performance tests
Understanding test-driven development (TDD)
Defining C# test projects
Using the xUnit test framework
Advanced test preparation and tear-down scenarios
Mocking interfaces with Moq
Use case – Automating unit tests in DevOps Azure
Connecting to an Azure DevOps repository
Summary
Questions
Further reading
Chapter 19: Using Tools to Write Better Code
Technical requirements
Identifying well-written code
Understanding and applying tools that can evaluate C# code
Applying extension tools to analyze code
Using Microsoft Code Analysis 2019
Applying SonarLint for Visual Studio 2019
Checking the final code after analysis
Use case – Evaluating C# code before publishing an application
Summary
Questions
Further reading
Chapter 20: Understanding DevOps Principles
Technical requirements
Describing DevOps
Understanding DevOps principles
Defining continuous integration
Understanding continuous delivery with Azure DevOps
Deploying our package-management application with Azure Pipelines
Creating the Azure Web App and the Azure database
Configuring your Visual Studio solution
Configuring Azure Pipelines
Adding a manual approval for the release
Creating a release
The multistage environment
Defining continuous feedback and the related DevOps tools
Monitoring software with Azure Monitor Application Insights
Using the Test and Feedback tool to enable feedback
Understanding SaaS
Adapting your organization to a service scenario
Developing software in a service scenario
Technical implications of a service scenario
Deciding when to adopt a SaaS solution
Preparing a solution for a service scenario
The WWTravelClub project approach
Summary
Questions
Further reading
Chapter 21: Challenges of Applying CI Scenarios
Technical requirements
Understanding CI
Continuous Integration and GitHub
Understanding the risks and challenges when using CI
Disabling continuous production deployment
Incomplete features
An unstable solution for testing
Understanding the WWTravelClub project approach
Summary
Questions
Further reading
Chapter 22: Automation for Functional Tests
Technical requirements
Understanding the purpose of functional tests
Using unit testing tools to automate functional tests in C#
Testing the staging application
Testing a controlled application
Use case – automating functional tests
Summary
Conclusions
Questions
Further reading
Answers
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Chapter 17
Chapter 18
Chapter 19
Chapter 20
Chapter 21
Chapter 22
Another Book You May Enjoy
Index