Software Architecture with C# 9 and .NET 5 - Second Edition

Book description

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. 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
    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 impacted system results
      1. Case 1 – my website is too slow to open that page!
        1. Understanding 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 user 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 5
      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 5
    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 Core
      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 Core 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 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 Service Fabric
    1. Technical requirements
      1. Visual Studio support for Azure Service Fabric
    2. Defining and configuring your Azure Service Fabric cluster
      1. Step 1 – Basic information
      2. Step 2 – Cluster configuration
      3. Step 3 – Security configuration
    3. Use case – Logging microservices
      1. Ensuring message idempotency
      2. The Interaction library
      3. Implementing the receiving side of communications
      4. Implementing service logic
      5. Defining the microservice's host
      6. Communicating with the service
      7. Testing the application
    4. Summary
    5. Questions
    6. Further reading
  8. 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
  9. 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. Querying and updating data with Entity Framework Core
      1. Returning data to the presentation layer
      2. Issuing direct SQL commands
      3. Handling transactions
    6. Deploying your data layer
    7. Understanding Entity Framework Core advanced features
    8. Summary
    9. Questions
    10. Further reading
  10. 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 structured or NoSQL storage
    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
  11. 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. 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
    6. Summary
    7. Questions
    8. Further reading
  12. Design Patterns and .NET 5 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 5
    4. Summary
    5. Questions
    6. Further reading
  13. 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. Using SOLID principles to map your domains
    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
  14. Implementing Code Reusability in C# 9
    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 5 or .NET Standard for code reuse
      1. Creating a .NET Standard 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
  15. Applying Service-Oriented Architectures with .NET Core
    1. Technical requirements
    2. Understanding the principles of the SOA approach
    3. SOAP web services
    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 5 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 Core HTTP clients
    6. Use case – exposing WWTravelClub packages
    7. Summary
    8. Questions
    9. Further reading
  16. Presenting ASP.NET Core MVC
    1. Technical requirements
    2. Understanding the presentation layers of web applications
    3. Understanding the ASP.NET Core MVC structure
      1. How the ASP.NET Core pipeline works
      2. Loading configuration data and using it with the options framework
      3. Defining the ASP.NET Core MVC pipeline
      4. Defining controllers and ViewModels
      5. Understanding Razor Views
        1. Learning the Razor flow of control statements
        2. Understanding Razor View properties
        3. Using Razor tag helpers
      6. Reusing view code
    4. What is new in the latest versions of ASP.NET Core?
    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. Use case – implementing a web app in ASP.NET Core MVC
      1. Defining application specifications
      2. Defining the application architecture
        1. Defining the domain layer
        2. Defining the data layer
        3. Defining the application layer
      3. Controllers and views
    7. Summary
    8. Questions
    9. Further reading
  17. 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. Events
      4. Bindings
      5. How Blazor updates HTML
      6. Component lifecycle
    4. Blazor forms and validation
    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. 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
  18. Best Practices in Coding C# 9
    1. Technical requirements
    2. The more complex your code, the worse a programmer you are
      1. Maintainability index
      2. Cyclomatic complexity
      3. Depth of inheritance
      4. Class coupling
      5. 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 5 tips and tricks for coding
    6. WWTravelClub – DOs and DON'Ts in writing code
    7. Summary
    8. Questions
    9. Further reading
  19. Testing Your Code with Unit Test Cases and TDD
    1. Technical requirements
    2. Understanding unit and integration tests
      1. Automating unit and integration tests
      2. Writing automated (unit and integration) tests
      3. Writing acceptance and performance tests
    3. Understanding test-driven development (TDD)
    4. Defining C# test projects
      1. Using the xUnit test framework
      2. Advanced test preparation and tear-down scenarios
      3. Mocking interfaces with Moq
    5. Use case – Automating unit tests in DevOps Azure
      1. Connecting to an Azure DevOps repository
    6. Summary
    7. Questions
    8. Further reading
  20. Using Tools to Write Better Code
    1. Technical requirements
    2. Identifying well-written code
    3. Understanding and applying tools that can evaluate C# code
    4. Applying extension tools to analyze code
      1. Using Microsoft Code Analysis 2019
      2. Applying SonarLint for Visual Studio 2019
    5. Checking the final code after analysis
    6. Use case – Evaluating C# code before publishing an application
    7. Summary
    8. Questions
    9. Further reading
  21. Understanding DevOps Principles
    1. Technical requirements
    2. Describing DevOps
    3. Understanding DevOps principles
      1. Defining continuous integration
    4. Understanding continuous delivery with Azure DevOps
      1. Deploying our package-management application with Azure Pipelines
        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
      2. The multistage environment
    5. Defining continuous feedback and the related DevOps tools
      1. Monitoring software with Azure Monitor Application Insights
      2. Using the Test and Feedback tool to enable feedback
    6. 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
    7. The WWTravelClub project approach
    8. Summary
    9. Questions
    10. Further reading
  22. Challenges of Applying CI Scenarios
    1. Technical requirements
    2. Understanding CI
    3. Continuous Integration and GitHub
    4. Understanding the risks and challenges when using CI
      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
  23. Automation for Functional Tests
    1. Technical requirements
    2. Understanding the purpose of functional tests
    3. Using unit testing tools to automate functional tests in C#
      1. Testing the staging application
      2. Testing a controlled application
    4. Use case – automating functional tests
    5. Summary
      1. Conclusions
    6. Questions
    7. Further reading
  24. Answers
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Chapter 15
    16. Chapter 16
    17. Chapter 17
    18. Chapter 18
    19. Chapter 19
    20. Chapter 20
    21. Chapter 21
    22. Chapter 22
  25. Another Book You May Enjoy
  26. Index

Product information

  • Title: Software Architecture with C# 9 and .NET 5 - Second Edition
  • Author(s): Gabriel Baptista, Francesco Abbruzzese
  • Release date: December 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781800566040