0%

Become a professional .NET developer by learning expert techniques for building enterprise-grade applications

Key Features

  • Explore the advanced features of C# and .NET 5 to enhance your code and productivity
  • Follow clear and easy instructions for building an end-to-end enterprise application
  • Learn how to build scalable web applications and host them on the cloud

Book Description

.NET Core is one of the most popular programming platforms in the world for an increasingly large community of developers thanks to its excellent cross-platform support. This book will show you how to confidently use the features of .NET 5 with C# 9 to build robust enterprise applications.

Throughout the book, you'll work on creating an enterprise app and adding a key component to the app with each chapter, before finally getting it ready for testing and deployment. You'll learn concepts relating to advanced data structures, the Entity Framework Core, parallel programming, and dependency injection. As you progress, you'll cover various authentication and authorization schemes provided by .NET Core to make your apps and APIs secure. Next, you'll build web apps using ASP.NET Core 5 and deploy them on the cloud while working with various cloud components using Azure. The book then shows you how to use the latest Microsoft Visual Studio 2019 and C# 9 to simplify developer tasks, and also explores tips and tricks in Visual Studio 2019 to improve your productivity. Later, you'll discover various testing techniques such as unit testing and performance testing as well as different methods to deploy enterprise apps.

By the end of this book, you'll be able to create enterprise apps using the powerful features of .NET 5 and deploy them on the cloud.

What you will learn

  • Design enterprise apps by making the most of the latest features of .NET 5
  • Discover di?erent layers of an app, such as the data layer, API layer, and web layer
  • Explore end-to-end architecture, implement an enterprise web app using .NET and C# 9, and deploy the app on Azure
  • Focus on the core concepts of web application development such as dependency injection, caching, logging, con?guration, and authentication, and implement them in .NET 5
  • Integrate the new .NET 5 health and performance check APIs with your app
  • Understand how .NET 5 works and contribute to the .NET 5 platform

Who this book is for

If you are a developer, architect, or senior programmer who wants to leverage the features of .NET 5 and the C# language, as well as grasp essential techniques to build your skills, then this C# .NET 5 book is for you. Beginner to intermediate-level knowledge of the .NET framework and C# programming is required to understand the concepts covered in this book more effectively.

Table of Contents

  1. Enterprise Application Development with C# 9 and .NET 5
  2. Contributors
  3. About the authors
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  6. Section 1: Architecting an Enterprise Application and its Fundamentals
  7. Chapter 1: Designing and Architecting the Enterprise Application
    1. Technical requirements
    2. A primer on common design principles and patterns
    3. Design principles
    4. Design patterns
    5. Understanding common enterprise architectures
    6. Common issues with monolithic apps
    7. Separation of concerns/single responsibility architecture
    8. Domain-driven architecture
    9. Stateless services architecture
    10. Event-driven architecture
    11. Data storage and access architecture
    12. Resiliency architecture
    13. Evolution and operations architecture
    14. Identifying enterprise application requirements (business and technical)
    15. The application's business requirements
    16. The application's technical requirements
    17. Architecting an enterprise application
    18. Solution structuring for an enterprise application
    19. Summary
    20. Questions
  8. Chapter 2: Introducing .NET 5 Core and Standard
    1. Technical requirements
    2. Introducing .NET 5
    3. Understanding the core features
    4. Understanding application frameworks
    5. Understanding the core components of .NET
    6. Setting up the development environment
    7. Understanding the CLI
    8. Overview of global.json
    9. What is .NET Standard?
    10. Understanding the use of .NET 5 and .NET Standard
    11. Understanding .NET 5 cross-platform and cloud application support
    12. Cloud support
    13. Summary
    14. Questions
    15. Further reading
  9. Chapter 3: Introducing C# 9
    1. Technical requirements
    2. Understanding Init-only setters
    3. Working with record types
    4. The with expression
    5. Understanding top-level statements
    6. Examining objects with pattern matching
    7. The constant pattern
    8. Type patterns
    9. Property patterns
    10. Conjunctive and disjunctive patterns
    11. Pattern matching with the switch expression
    12. Tuple patterns
    13. Understanding type inference with target-typed expressions
    14. Understanding static anonymous functions
    15. Eager initialization with module initializers
    16. Summary
    17. Questions
  10. Section 2: Cross-Cutting Concerns
  11. Chapter 4: Threading and Asynchronous Operations
    1. Technical requirements
    2. Understanding the jargon
    3. Demystifying threads, lazy initialization, and ThreadPool
    4. Working with System.Threading.Thread
    5. ThreadPool
    6. Lazy initialization
    7. Understanding locks, semaphores, and SemaphoreSlim
    8. The critical section and thread safety
    9. Introducing locks
    10. Mutex (Windows only)
    11. Introducing semaphores and SemaphoreSlim
    12. Choosing the right synchronization constructs
    13. Introducing tasks and parallels
    14. Introduction to Task and the TPL
    15. Handling task exceptions
    16. Implementing task cancellation
    17. Implementing continuations
    18. SynchronizationContext
    19. TaskScheduler
    20. Implementing data parallelism
    21. Using Parallel LINQ (PLINQ)
    22. Introducing async-await
    23. The task-based asynchronous pattern
    24. Principles of using async-await
    25. Async streams with IAsyncEnumerable
    26. Wrappers for legacy patterns
    27. ThreadPool starvation
    28. Using concurrent collections for parallelism
    29. ConcurrentDictionary
    30. Producer-consumer concurrent collections
    31. The BlockingCollection<T> class
    32. Summary
    33. Questions
    34. Further reading
  12. Chapter 5: Dependency Injection in .NET
    1. Technical requirements
    2. What is DI?
    3. Types of DI
    4. DI in ASP.NET Core 5
    5. Understanding service lifetimes
    6. Managing application services
    7. DI in Razor Pages
    8. Using third-party containers
    9. Summary
    10. Questions
  13. Chapter 6: Configuration in .NET Core
    1. Technical requirements
    2. Understanding configuration
    3. Default configuration
    4. Adding configurations
    5. Reading configurations
    6. Leveraging built-in configuration providers
    7. Azure Key Vault configuration provider
    8. File configuration provider
    9. Building a custom configuration provider
    10. Configuration source
    11. Configuration provider
    12. Configuration extension
    13. Summary
    14. Questions
    15. Further reading
  14. Chapter 7: Logging in .NET 5
    1. Technical requirements
    2. Characteristics of good logging
    3. Understanding the available logging providers
    4. Built-in logging providers
    5. Third-party logging providers
    6. Working with Azure App Service
    7. Enabling application logging in Azure App Service
    8. Monitoring using metrics
    9. Alerting using metrics
    10. Real-time telemetry in Azure Application Insights
    11. Enabling application logging in Application Insights
    12. Creating a .NET 5 logging class library
    13. Summary
    14. Questions
  15. Chapter 8: Understanding Caching
    1. Technical requirements
    2. Introduction to caching
    3. Client caching
    4. Content Delivery Network (CDN)
    5. Web server caching
    6. Database caching
    7. Application caching
    8. Understanding the components of caching
    9. Response caching
    10. Distributed caching
    11. Cache access patterns
    12. Caching platforms
    13. In-memory cache
    14. Distributed cache
    15. Designing a cache abstraction layer using distributed caching
    16. Caching considerations
    17. Summary
    18. Questions
    19. Further reading
  16. Section 3: Developing Your Enterprise Application
  17. Chapter 9: Working with Data in .NET 5
    1. Technical requirements
    2. Introduction to data
    3. Relational Database Management System (RDBMS)
    4. NoSQL
    5. Disks, files, and directories
    6. Handling directories
    7. Reading/writing data with streams, binary, and strings
    8. Streams
    9. Reader/writer
    10. TextReader/TextWriter versus BinaryReader/BinaryWriter
    11. JSON.NET
    12. SQL, Azure Cosmos DB, and Azure Storage
    13. SQL Server
    14. Azure Cosmos DB
    15. Azure Storage
    16. Working with EF Core
    17. Configuration and querying
    18. Code first versus database first
    19. Designing a Data access service using Azure Cosmos DB
    20. Summary
    21. Questions
    22. Further reading
  18. Chapter 10: Creating an ASP.NET Core 5 Web API
    1. Technical requirements
    2. Introduction to Representational State Transfer (REST)
    3. The REST maturity model
    4. Understanding the internals of an ASP.NET Core 5 web API
    5. Program and Startup classes
    6. Understanding middleware
    7. Building a custom middleware
    8. Handling requests using controllers and actions
    9. Understanding ASP.NET Core routing
    10. Attribute-based routing
    11. The ControllerBase class, the ApiController attribute, and the ActionResult class
    12. Integration with the data layer
    13. Creating DTOs
    14. Service class contracts
    15. The mapper class using AutoMapper
    16. HttpClient factory for service-to-service calls
    17. Implementing service classes
    18. Implementing action methods in the controller
    19. Understanding gRPC
    20. Building a gRPC server in .NET
    21. Building a gRPC client in .NET
    22. Testing gRPC services
    23. Summary
    24. Questions
    25. Further reading
  19. Chapter 11: Creating an ASP.NET Core 5 Web Application
    1. Technical requirements
    2. Introduction to frontend web development
    3. Razor syntax
    4. Exploring Razor Pages
    5. Exploring the ASP.NET Core MVC website
    6. Understanding single-page applications
    7. Integrating APIs with the service layer
    8. Creating the controller and actions
    9. Creating a UI using ASP.NET Core MVC
    10. Setting up AdminLTE, the Layout page, and views
    11. Understanding Blazor
    12. Summary
    13. Questions
    14. Further reading
  20. Section 4: Security
  21. Chapter 12: Understanding Authentication
    1. Technical requirements
    2. Understanding the elements of authentication in .NET 5
    3. Introduction to ASP.NET Core Identity
    4. Sample implementation
    5. Scaffolding
    6. Integration with external login providers
    7. Understanding OAuth 2.0
    8. Tokens
    9. Authorization grant types
    10. Introduction to Azure AD
    11. Azure AD B2C setup
    12. Integration of our e-commerce application to Azure AD B2C
    13. Introduction to Windows Authentication
    14. Understanding best practices to secure client and server applications
    15. Summary
    16. Questions
    17. Further reading
  22. Chapter 13: Understanding Authorization
    1. Technical requirements
    2. Back to a few basics
    3. Understanding authorization
    4. Simple authorization
    5. Enabling authorization globally
    6. Role-based authorization
    7. Policy-based role authorization
    8. Implementing role-based authorization
    9. Claim-based authorization
    10. Policy-based authorization
    11. Requirements
    12. Requirement handlers
    13. Registering a policy
    14. Custom authorization
    15. Custom authorization attributes
    16. Authorization in client and server applications
    17. Assigning roles to users
    18. User identity in views
    19. Summary
    20. Questions
    21. Further reading
  23. Section 5: Health Checks, Unit Testing, Deployment, and Diagnostics
  24. Chapter 14: Health and Diagnostics
    1. Technical requirements
    2. Introducing health checks
    3. The health check API in ASP.NET Core 5
    4. Adding a health check endpoint
    5. Monitoring dependent URIs
    6. Building a custom health check
    7. Monitoring the application with Application Insights
    8. Live Metrics
    9. Usage analysis with Application Insights
    10. Smart Detection
    11. Application availability
    12. Search
    13. Logs
    14. Snapshot Debugger
    15. Performing remote debugging
    16. Summary
    17. Questions
    18. Further reading
  25. Chapter 15: Testing
    1. Technical requirements
    2. Introducing testing
    3. Understanding unit testing
    4. Unit testing in Visual Studio
    5. Code coverage
    6. Understanding functional testing
    7. Automating functional test cases
    8. Understanding load testing
    9. Load testing with JMeter
    10. Summary
    11. Questions
  26. Chapter 16: Deploying the Applications in Azure
    1. Technical requirements
    2. Introducing Azure DevOps
    3. Boards
    4. Repos
    5. Pipelines
    6. Test plans
    7. Artifacts
    8. Understanding the CI pipeline
    9. Understanding the flow and components of a pipeline
    10. Understanding the CD pipeline
    11. Continuous deployment versus continuous delivery
    12. Deploying an ASP.NET 5 application
    13. Creating a pipeline for CI and CD
    14. Summary
    15. Questions
    16. Further reading
  27. Assessments
    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. Why subscribe?
  28. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think
18.190.156.212