Software Architecture with C# 10 and .NET 6 - Third Edition

Book description

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

Key Features

  • Gain comprehensive software architecture knowledge and the skillset to create fully modular apps
  • Solve scalability problems in web apps using enterprise architecture patterns
  • Master new developments in front-end architecture and the application of AI for software architects

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 third edition, featuring the latest features of .NET 6 and C# 10, enables you to acquire the key skills, knowledge, and best practices required to become an effective software architect.

Software Architecture with C# 10 and .NET 6, Third Edition features new chapters that describe the importance of the software architect, microservices with ASP.NET Core, and analyzing the architectural aspects of the front-end in the applications, including the new approach of .NET MAUI. It also includes a new chapter focused on providing a short introduction to artificial intelligence and machine learning using ML.NET, and updated chapters on Azure Kubernetes Service, EF Core, and Blazor.

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 choose a cloud solution for your infrastructure, taking into account the factors that will help you manage a cloud-based app successfully. Finally, you will analyze and implement software design patterns that will allow you to solve common development problems.

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

What you will learn

  • Use proven techniques to overcome real-world architectural challenges
  • Apply architectural approaches such as layered architecture
  • Leverage tools such as containers to manage microservices effectively
  • Get up to speed with Azure features for delivering global solutions
  • Program and maintain Azure Functions using C# 10
  • Understand when it is best to use test-driven development (TDD)
  • Implement microservices with ASP.NET Core in modern architectures
  • Enrich your application with Artificial Intelligence
  • 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. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Get in touch
  2. Understanding the Importance of Software Architecture
    1. What is software architecture?
      1. Creating an Azure account
    2. Software development process models
      1. Reviewing traditional software development process models
        1. Understanding the waterfall model principles
        2. Analyzing the incremental model
      2. Understanding agile software development process models
        1. Lean software development
        2. Extreme Programming
        3. Getting into the Scrum model
        4. Scaling agile throughout a company
    3. Gathering the right information to design high-quality software
      1. Understanding the requirements gathering process
      2. Detecting exact user needs
      3. Analyzing requirements
      4. Writing the specifications
        1. Understanding the principles of scalability, robustness, security, and performance
      5. Reviewing the specification
    4. Using design techniques as a helpful tool
      1. Design Thinking
      2. Design Sprint
    5. Common cases where the requirements gathering process impacts system results
      1. Case 1 – my website is too slow to open that page!
        1. Understanding backend caching
        2. Applying asynchronous programming
        3. Dealing with object allocation
        4. Getting better database access
      2. Case 2 – the user’s needs are not properly implemented
      3. Case 3 – the usability of the system does not meet the user’s needs
    6. Case study – introducing World Wild Travel Club
      1. Understanding user needs and system requirements
    7. Summary
    8. Questions
    9. Further reading
  3. Non-Functional Requirements
    1. Technical requirements
    2. Enabling scalability, availability, and resiliency with Azure and .NET 6
      1. Creating a scalable web app in Azure
        1. Vertical scaling (scaling up)
        2. Horizontal scaling (scaling out)
      2. Creating a scalable web app with .NET 6
    3. Performance issues that need to be considered when programming in C#
      1. String concatenation
      2. Exceptions
      3. Multithreading environments for better results – dos and don’ts
    4. Usability – why inserting data takes too much time
      1. Designing fast selection logic
      2. Selecting from a huge number of items
    5. The fantastic world of interoperability with .NET 6
      1. Creating a service in Linux
    6. Achieving security by design
      1. List of practices for achieving a safe architecture
        1. Authentication
        2. Sensitive data
        3. Web security
    7. Book use case – understanding the main types of .NET projects
    8. Summary
    9. Questions
    10. Further reading
  4. Documenting Requirements with Azure DevOps
    1. Technical requirements
    2. Introducing Azure DevOps
    3. Organizing your work using Azure DevOps
      1. Azure DevOps repository
      2. Package feeds
      3. Test Plans
      4. Pipelines
    4. Managing system requirements in Azure DevOps
      1. Epic work items
      2. Feature work items
      3. Product Backlog items/User Story work items
    5. Use case – presenting use cases in Azure DevOps
    6. Summary
    7. Questions
    8. Further reading
  5. Deciding on the Best Cloud-Based Solution
    1. Technical requirements
    2. Different software deployment models
      1. IaaS and Azure opportunities
        1. Security responsibility in IaaS
      2. PaaS – a world of opportunities for developers
        1. Web apps
        2. SQL databases
        3. Azure Cognitive Services
      3. SaaS – just sign in and get started!
      4. Understanding what serverless means
    3. Why are hybrid applications so useful in many cases?
    4. Book use case – which is the best cloud solution?
    5. Summary
    6. Questions
    7. Further reading
  6. Applying a Microservice Architecture to Your Enterprise Application
    1. Technical requirements
    2. What are microservices?
      1. Microservices and the evolution of the concept of modules
      2. Microservices design principles
        1. The independence of design choices
        2. Independence from the deployment environment
        3. Loose coupling
        4. No chained requests/responses
      3. Containers and Docker
    3. When do microservices help?
      1. Layered architectures and microservices
        1. The presentation layer
      2. When is it worth considering microservice architectures?
    4. How does .NET deal with microservices?
      1. .NET communication facilities
      2. Resilient task execution
      3. Using generic hosts
      4. Visual Studio support for Docker
        1. Analyzing the Docker file
        2. Publishing the project
      5. Azure and Visual Studio support for microservice orchestration
    5. Which tools are needed to manage microservices?
      1. Defining your private Docker registry in Azure
    6. Summary
    7. Questions
    8. Further reading
  7. Azure Kubernetes Service
    1. Technical requirements
    2. Kubernetes basics
      1. .yaml files
      2. ReplicaSets and Deployments
      3. StatefulSets
      4. Services
      5. Ingresses
    3. Interacting with Azure Kubernetes clusters
      1. Using Kubectl
      2. Deploying the demo Guestbook application
    4. Advanced Kubernetes concepts
      1. Requiring permanent storage
      2. Kubernetes secrets
      3. Liveness and readiness checks
      4. Autoscaling
      5. Helm – Installing an Ingress Controller
    5. Summary
    6. Questions
    7. Further reading
  8. Interacting with Data in C# – Entity Framework Core
    1. Technical requirements
    2. Understanding ORM basics
    3. Configuring Entity Framework Core
      1. Defining DB entities
      2. Defining the mapped collections
      3. Completing the mapping configuration
    4. Entity Framework Core migrations
      1. Understanding stored procedures and direct SQL commands
    5. Compiled models
    6. Querying and updating data with Entity Framework Core
      1. Returning data to the presentation layer
      2. Issuing direct SQL commands
      3. Handling transactions
    7. Deploying your data layer
    8. Understanding Entity Framework Core advanced features
    9. Summary
    10. Questions
    11. Further reading
  9. How to Choose Your Data Storage in the Cloud
    1. Technical requirements
    2. Understanding the different repositories for different purposes
      1. Relational databases
      2. NoSQL databases
      3. Redis
      4. Azure storage accounts
    3. Choosing between SQL or NoSQL document-oriented databases
    4. Azure Cosmos DB – an opportunity to manage a multi-continental database
      1. Creating an Azure Cosmos DB account
      2. Creating an Azure Cosmos container
      3. Accessing Azure Cosmos data
      4. Defining database consistency
      5. The Cosmos DB client
      6. The Cosmos DB Entity Framework Core provider
    5. Use case – storing data
      1. Implementing the destinations/packages database with Cosmos DB
    6. Summary
    7. Questions
    8. Further reading
  10. Working with Azure Functions
    1. Technical requirements
    2. Understanding the Azure Functions app
      1. Consumption plan
      2. Premium plan
      3. App Service plan
    3. Programming Azure Functions using C#
      1. Listing Azure Functions templates
    4. Maintaining Azure Functions
    5. Azure Durable Functions
    6. Azure Functions roadmap
    7. Use case – Implementing Azure Functions to send emails
      1. First step – Creating Azure queue storage
      2. Second step – Creating the function to send emails
      3. Third step – Creating the queue trigger function
    8. Summary
    9. Questions
    10. Further reading
  11. Design Patterns and .NET 6 Implementation
    1. Technical requirements
    2. Understanding design patterns and their purpose
      1. Builder pattern
      2. Factory pattern
      3. Singleton pattern
      4. Proxy pattern
      5. Command pattern
      6. Publisher/Subscriber pattern
      7. Dependency Injection pattern
    3. Understanding the available design patterns in .NET 6
    4. Summary
    5. Questions
    6. Further reading
  12. Understanding the Different Domains in Software Solutions
    1. Technical requirements
    2. What are software domains?
    3. Understanding domain-driven design
    4. Entities and value objects
    5. Layers and the Onion architecture
    6. Aggregates
    7. The repository and Unit of Work patterns
    8. DDD entities and Entity Framework Core
    9. Command Query Responsibility Segregation (CQRS) pattern
    10. Command handlers and domain events
    11. Event sourcing
    12. Use case – understanding the domains of the use case
    13. Summary
    14. Questions
    15. Further reading
  13. Implementing Code Reusability in C# 10
    1. Technical requirements
    2. Understanding the principles of code reusability
      1. What is not code reuse?
      2. What is code reuse?
    3. Reusability in the development life cycle
    4. Using .NET 6 for code reuse
      1. Creating a reusable class library
    5. How does C# deal with code reuse?
      1. Object-oriented analysis
      2. Generics
    6. What if the code is not reusable?
    7. I have my libraries. How do I promote them?
      1. Documenting .NET libraries using DocFX
      2. Documenting a Web API using Swagger
    8. Use case – reusing code as a fast way to deliver good and safe software
    9. Summary
    10. Questions
    11. Further reading
  14. Applying Service-Oriented Architectures with .NET
    1. Technical requirements
    2. Understanding the principles of the SOA approach
    3. SOAP web services
      1. SOAP specifications
      2. Difficulties associated with the standard
    4. REST web services
      1. Service type compatibility rules
      2. REST and native HTTP features
      3. Example of methods in the REST language
      4. The OpenAPI standard
      5. REST service authorization and authentication
    5. How does .NET 6 deal with SOA?
      1. SOAP client support
      2. gRPC support
      3. A short introduction to ASP.NET Core
      4. Implementing REST services with ASP.NET Core
        1. ASP.NET Core service authorization
        2. ASP.NET Core support for OpenAPI
        3. .NET HTTP clients
    6. Use case – exposing WWTravelClub packages
    7. Summary
    8. Questions
    9. Further reading
  15. Implementing Microservices with .NET
    1. Technical requirements
    2. Communication and data serialization
      1. Efficient and flexible binary serialization
        1. The ProtoBuf language
        2. ProtoBuf serialization
      2. Efficient and flexible RPC
      3. Reliable data-driven asynchronous communication
      4. Distributed transactions
    3. Implementing worker microservices with ASP.NET core
      1. The problem and the architecture
      2. The storage layer
      3. The application layer
      4. Processing the queued requests
      5. Testing the GrpcMicroservice project with a fake purchase requests generator
    4. Implementing microservices with .NET worker services and message brokers
      1. Installing RabbitMQ
      2. RabbitMQ basics
      3. Replacing internal queues with RabbitMQ
    5. Summary
    6. Questions
    7. Further reading
  16. Presenting ASP.NET Core MVC
    1. Technical requirements
    2. Understanding the presentation layers of web applications
    3. Understanding the basics of ASP.NET Core
      1. ASP.NET Core middleware
      2. Loading configuration data and using it with the options framework
      3. Defining the ASP.NET Core pipeline
      4. Defining controllers and ViewModels
    4. Understanding how ASP.NET Core MVC creates the response HTML
      1. Razor Views
        1. Learning the Razor flow of control statements
        2. Understanding Razor View properties
        3. Using Razor tag helpers
      2. Reusing view code
    5. Understanding the connection between ASP.NET Core MVC and design principles
      1. Advantages of the ASP.NET Core pipeline
      2. Server-side and client-side validation
      3. ASP.NET Core globalization
      4. The MVC pattern
    6. Summary
    7. Questions
    8. Further reading
  17. Implementing Frontend Microservices with ASP.NET Core
    1. Technical requirements
    2. Frontends and micro-frontends
      1. Public web APIs
      2. HTML micro-frontends
    3. Application specifications and architecture
      1. Defining application specifications
      2. Defining the application architecture
    4. Defining the domain layer abstraction
    5. Defining the data layer
    6. Defining the application layer
    7. Defining controllers and views
    8. Summary
    9. Further reading
  18. Blazor WebAssembly
    1. Technical requirements
    2. Blazor WebAssembly architecture
      1. What is a single-page application?
      2. Loading and starting the application
      3. Routing
    3. Blazor pages and components
      1. Component structure
      2. Templates and cascading parameters
      3. Error handling
      4. Events
      5. Bindings
      6. How Blazor updates HTML
      7. Component lifecycle
    4. Blazor forms and validation
      1. Modifying HTML <head> content from Blazor components
    5. Blazor advanced features
      1. References to components and HTML elements
      2. JavaScript interoperability
      3. Globalization and localization
      4. Authentication and authorization
      5. Communication with the server
      6. AOT compilation
    6. Third-party tools for Blazor WebAssembly
    7. Use case – implementing a simple application in Blazor WebAssembly
      1. Preparing the solution
      2. Implementing the required ASP.NET Core REST APIs
      3. Implementing the business logic in a service
      4. Implementing the user interface
    8. Summary
    9. Questions
    10. Further reading
  19. Native versus Web Clients
    1. Technical requirements
    2. Technologies focused on native development
      1. Windows Forms
      2. Windows Presentation Foundation (WPF)
      3. Xamarin
    3. Technologies focused on web development
      1. Progressive web applications
    4. Cross-platform technologies
      1. Xamarin.Forms
      2. .NET MAUI
    5. A first look at .NET MAUI
      1. .NET MAUI Blazor applications
    6. Summary
    7. Questions
    8. Further reading
  20. Artificial Intelligence and Machine Learning
    1. Technical requirements
    2. Introduction to AI and machine learning
    3. Classification of the most common artificial intelligence techniques
      1. Heuristic search
      2. First-order calculus
      3. Planners
      4. Heuristic rules, neural networks, and Bayesian networks
      5. Truth maintenance systems
    4. What is machine learning and why does it work?
      1. Machine learning basics
      2. How many examples do I need to learn my function?
      3. Learning smooth functions
        1. Neural networks
        2. The support vector algorithm
      4. Learning small computer programs: induction-based learning
    5. From theory to practice: the role of a software architect in an ML project
      1. Step 1 – Define your goal
      2. Step 2 – Provide and prepare data
      3. Step 3 – Train, tune, and deploy your model
      4. Step 4 – Test the trained model and feed back on it
    6. ML.NET – Machine learning made for .NET
      1. ML.NET Model Builder
    7. Summary
    8. Questions
    9. Further reading
  21. Best Practices in Coding C# 10
    1. Technical requirements
    2. The simpler your code, the better a programmer you are
      1. Maintainability index
      2. Cyclomatic complexity
      3. Depth of inheritance
      4. Class coupling
      5. Number of lines of code
    3. Using a version control system
      1. Dealing with version control systems in teams
    4. Writing safe code in C#
      1. try-catch
      2. try-finally and using
      3. The IDisposable interface
    5. .NET 6 tips and tricks for coding
    6. Identifying well-written code
      1. Understanding and applying tools that can evaluate C# code
      2. Applying extension tools to analyze code
        1. Applying SonarAnalyzer
        2. Checking the final code after analysis
    7. Applying this chapter to the WWTravelClub sample project
      1. WWTravelClub – DOs and DON’Ts in writing code
      2. WWTravelClub – Evaluating C# code before publishing an application
    8. Summary
    9. Questions
    10. Further reading
  22. Understanding DevOps Principles
    1. Technical requirements
    2. Describing DevOps
    3. Understanding DevOps principles
      1. Defining continuous integration
      2. Understanding continuous delivery with Azure DevOps
        1. Creating the Azure Web App and the Azure database
        2. Configuring your Visual Studio solution
        3. Configuring Azure Pipelines
        4. Adding a manual approval for the release
        5. Creating a release
        6. The multistage environment
      3. Defining continuous feedback and the related DevOps tools
        1. Monitoring software with Application Insights
        2. Using the Test and Feedback tool to enable feedback
    4. Understanding SaaS
      1. Adapting your organization to a service scenario
      2. Developing software in a service scenario
      3. Technical implications of a service scenario
      4. Deciding when to adopt a SaaS solution
      5. Preparing a solution for a service scenario
    5. The WWTravelClub project approach
    6. Summary
    7. Questions
    8. Further reading
  23. Challenges of Applying CI & CD Scenarios
    1. Technical requirements
    2. Understanding CI/CD
    3. CI/CD and GitHub
    4. Understanding the risks and challenges when using CI/CD
      1. Disabling continuous production deployment
      2. Incomplete features
      3. An unstable solution for testing
    5. Understanding the WWTravelClub project approach
    6. Summary
    7. Questions
    8. Further reading
  24. Testing Your Enterprise Application
    1. Technical requirements
    2. Understanding unit and integration tests
      1. Automating unit and integration tests
      2. Writing automated (unit and integration) tests
      3. Acceptance tests: writing functional and performance tests
    3. Understanding test-driven development
    4. Functional tests
    5. Defining C# test projects in Visual Studio
      1. Using the xUnit test framework
      2. Advanced test preparation and tear-down scenarios
      3. Mocking interfaces with Moq
    6. Automating functional tests in C#
      1. Testing the staging application
      2. Testing the staging application with Selenium
      3. Testing a controlled application
    7. Use case – automating unit and functional tests
      1. Automating functional tests
      2. Connecting to an Azure DevOps repository
    8. Summary
    9. Questions
    10. Further reading
  25. Answers
  26. Other Books You May Enjoy
  27. Index

Product information

  • Title: Software Architecture with C# 10 and .NET 6 - Third Edition
  • Author(s): Gabriel Baptista, Francesco Abbruzzese
  • Release date: March 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781803235257