Enterprise Application Development with C# 9 and .NET 5

Book description

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

Product information

  • Title: Enterprise Application Development with C# 9 and .NET 5
  • Author(s): Ravindra Akella, Arun Kumar Tamirisa, Suneel Kumar Kunani, Bhupesh Guptha Muthiyalu
  • Release date: March 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781800209442