This .NET 5.0 training course introduces developers who are already familiar with .NET and web development to the new features introduced in .NET 5.0, Microsoft’s cross-platform, open-source implementation of .NET. It represents the successor to .NET Core and the unification with the Windows-only .NET Framework. Like .NET Core., NET 5.0 can run on Windows, Linux, and Mac operating systems and a variety of different devices. Similarly, ASP.NET Core 5.0, initially referred to as ASP.NET 5, represents the current and future platform for web applications in .NET and provides cross-platform support with flexible hosting options.
The primary emphasis is on presenting what’s new in .NET 5.0 and highlighting its differences with both .NET Core and .NET Framework. These new features are presented in the context of developing an ASP.NET Core 5.0 Web API Server that is scalable and testable and follows modern best practices.
Key Learning Areas
- Understand the architecture, features and design goals of .NET 5.0
- Build .NET 5 applications from the command line and Visual Studio
- Deploy .NET 5 applications, discussing all available models
- Write code using the new features introduced in C# 9.0
- Create an ASP.NET Core 5.0 Web API Server
- Configure the ASP.NET Core 5.0 server
- Access database info for the server using Entity Framework Core 5.0
- Abstract the data access details using the repository design pattern
- Manually create a mock repository
- Automatically create a mock repository with Moq
- Inject the repository with ASP.NET Core 5 dependency injection (DI)
- Unit test code generic code with xUnit
- Unit test the ASP.NET Core 5 controller with xUnit, DI and Moq
- Publish the server to the cloud with an Azure App Service
The course begins with a general introduction to the motivation and architecture underlying .NET 5.0. The tools for creating, building and running a .NET 5.0 application are presented, through the use of both the command line and Visual Studio. This module also thoroughly covers the details of how to create and use class libraries in .NET 5.0, and the compilation options for building binaries.
- What is .NET 5.0 and why write applications for it
- Developing applications for .NET 5.0
- Command line/dotnet.exe
- Visual Studio
- Libraries for .NET 5.0
- NuGet Metapackages
- Distributing a class library through NuGet
- Compilation options
- Tired compilation
- Quick JIT
Deploying a .NET 5.0 Application
After successfully creating and building a .NET 5.0 application, the next step is to publish it for production. .NET 5.0 developers can choose between: (1) a minimal deployment, assuming that everything necessary to run the application is already installed on the client machine, (2) a large, multi-file, self-contained deployment that has everything necessary to run the application on the client machine, or (3) a large, single-file, self-contained deployment. This module demonstrates how to use all three of these options, and their accompanying features, from both the command line and Visual Studio.
- Deployment models
- Framework-dependent deployment (FDD)
- Self-contained deployment (SCE)
- Trim mode
- Framework-dependent executables (FDE)
- Single file executables
ASP.NET Core 5.0
Web development requires an understanding of ASP.NET Core 5.0, and this module thoroughly covers the anatomy of an ASP.NET Core 5.0 application. The internal details of the code generated by the Visual Studio “ASP.NET Core Web Application” project template are covered in depth, specifically CreateHostBuilder in the program’s Main, and all of the Configure code in the program’s Startup class. The importance of middleware in writing a modern server application is emphasized, along with how to use existing middleware available through NuGet, and how to write custom middleware. The coverage concludes with a discussion of error handling best practices for development and production builds.
- Architecture of ASP.NET Core 5.0
- Hosting options
- Startup code
- Error handling
Repository and Unit of Work Patterns
Data access is an essential part of writing a server application. It is critical that server applications follow the established best practices for separating the data access code from the business logic. Providing that separation facilitates changes to the underlying data store and makes the code unit testable. This module presents the two primary design patterns for achieving this proper separation of concerns: The Repository Pattern, for abstracting from the application the details of the data store, and the Unit of Work pattern, for proper access to multiple repositories that share a single context.
- How to separate application logic from data access
- Best practices for writing a repository interface
- Best practices for accessing multiple repositories through Unit of Work
ASP.NET Core 5.0 Web API
This module introduces Web API, the de facto framework for building HTTP-based RESTful services. It covers the motivation for HTTP oriented services as an alternative to SOAP-based services. The architecture of an ASP.NET Core 5.0 Web API application is examined, including convention and attribute-based routing. Finally, the module concludes with the client-side programming model for HTTP services with the HttpClient API.
- REST Basics
- Web API controllers
- Web API routing
- CRUD operations
- .NET Web API Client
Tightly coupled systems are less flexible because they make it difficult to swap out components should they become outdated or need to be replaced. In addition, the code becomes less testable, because unit tests are unable to replace dependencies with fakes, turning unit tests into integration tests, which are slower and prone to breakage. This module addresses these issues through the ASP.NET Core 5.0 built-in dependency injection container.
- Dependency Injection in ASP.NET Core 5.0
- Constructor and method injection
- Lifetime models: singleton vs. transient vs. scoped
- Creating services and injecting them into a web application
ASP.NET Core 5.0 Configuration
ASP.NET Core 5.0 configuration files operate differently from the traditional app.config and web.config files from .NET Framework. In an ASP.NET Core 5.0 application, configuration information is typically specified with json format using an appsettings.json file. This module demonstrates how configuration files are formatted and parsed in an ASP.NET Core 5.0 application.
- Initialization and retrieval from the ASP.NET Core 5.0 configuration file
- Binding and reloading
Entity Framework Core 5.0
Modern server applications are required to manage large amounts of data, which are typically obtained through queries to a database. This module presents Entity Framework Core 5.0, Microsoft’s cross platform, object relational mapping technology for writing data access code using .NET objects. The emphasis is on the differences between using Entity Framework vs. Entity Framework Core 5.0 both in tooling and in writing code.
- Comparison of Entity Framework and Entity Framework Core 5.0
- Entity Framework Core 5.0 with database first
- Installing EF Core 5.0 with Visual Studio
- Creating the model from an existing database
- Understanding the generated data access code
Testing is a critical aspect of the software development process, and xUnit is the de facto testing framework for .NET 5.0. This module starts with the definition, best practices, naming conventions, and techniques for unit tests. It then covers the basics of xUnit, highlighting the differences between Fact vs. Theory. The module concludes with a demonstration of how to unit test the methods of an ASP.NET Core 5.0 controller using manually mocked data.
- Unit testing fundamentals
- Using xUnit with Visual Studio
- Testing code that generates exceptions
- Testing an ASP.NET Core 5.0 Controller with manual mocking
Mocking with Moq
Test doubles and mocking frameworks make it easier to stub out external dependencies. Moq has emerged as the de facto standard mocking framework for .NET 5.0, and this module covers the details of how to use it to mock interfaces, objects, classes, methods, and properties.
- State vs Behavior verification
- The different forms of Test Doubles
- Moq as an example of a mocking framework
- Stubs: Properties and Methods
- Mocks: Strict, Loose and Partial
Unit Testing a Web API Controller using xUnit and Moq
This section represents the culmination of all the material covered in this course. It shows how to use the techniques previously presented to complete the production of a scalable Web API server that is unit-testable and follows modern best practices. It looks at how to use Dependency Injection and the Repository Pattern for writing controllers that are easier to test, as well as how to use Moq to make it easier to stub out external dependencies.
- Unit test the methods of an ASP.NET Core 5.0 Web API Controller using xUnit and Moq
Deploying the Server to the Azure cloud
The modern way to deploy an ASP.NET Core 5.0 application is to publish it to the cloud. This module provides an introduction to the Azure cloud-based deployment options. It demonstrates how to publish an ASP .NET Core 5.0 application to an App Service in Azure using Visual Studio. The module concludes with a discussion of the benefits of an Azure deployment, such as scale-up, scale-out, and deployment slots.
- Introduction to the cloud and Azure
- Publishing an application to an App Service in Azure
- The benefits of deploying an application to Azure
Accompanying the release of .NET 5.0 is a new release of C#. This module presents C# 9.0, with features that can make code simpler and more clear through the added language support for immutability and compactness.
- Init-only properties
- Top-level statements
- Record types
- Target typing
- Pattern matching improvements
- High performance and interop features
- Coding efficiency features
This module discusses how to migrate an existing .NET application to .NET 5.0. It also presents the options and recommended guidance for porting existing libraries, written for.NET Framework, .NET Core, and .NET Standard, to .NET 5.0.
- Strategies and tools for porting an existing application
- .NET Framework technologies discontinued in .NET 5.0
- Porting from an earlier version of .NET Core to 5.0
- Porting an ASP.NET Framework Controller to .NET 5.0
- Porting existing libraries to .NET 5.0
Performing I/O-Bound Asynchronous Operations in a Scalable Server
This section explains how to identify I/O-bound operations and how to execute those operations asynchronously using the C# 5.0 async and await keywords. The techniques covered demonstrate how to reduce the resources required by a server while increasing performance.
- How Windows performs synchronous and asynchronous I/O operations
- How to use the async and await keywords to simplify writing asynchronous code
- Using .NET’s Asynchronous Programming model for streams, sockets, database requests, web service requests, and more
- How to properly architect concurrency in an ASP.NET Core 5.0 scalable server application
- What the C# compiler generates from the async and await keywords
- Special considerations required for GUI and ASP.NET applications (using SynchronizationContext to connect an application model to its threading model)
Debugging in Production with WinDBG
No network administrator managing production servers is ever going to let you install Visual Studio on a production box. What you are going to get off a production server is a minidump, which is a snapshot of all the memory your .NET application is using. In order to analyze those minidumps, a different
debugger is required: WinDBG, the most powerful debugger available on Windows. In order to debug .NET applications with WinDBG, knowledge of SOS is essential. SOS is one of those tools that gives you all the power in the world, but offers no easy way to get started on using that power. This module introduces the fundamentals of WinDBG and SOS.
- The basics of WinDbg
- WinDbg regular commands for debugging
- WinDbg meta commands for debugging
- WinDbg extension commands for debugging
- Loading and using SOS
- Process state SOS commands
- Using SOSEX to fix SOS limitations
- SOS heap commands
- Finding reference SOS commands
- Solving multithreaded deadlocks with SOS and WinDBG
.NET Core and/or .NET Framework and are looking to: (1) modernize their applications to run on .NET 5.0 and (2) create a testable and scalable ASP.NET Core 5.0 server.
- .NET Core or .NET Framework programming experience
- C# programming experience