.NET 7.0
The course begins with a general introduction to the motivation and architecture underlying .NET 7.0. This module covers the goals and general features of .NET 7.0, as well as the older technologies that are not ported. A discussion of the .NET versions and release cycles is also covered.
- What is .NET 7.0 and why write applications for it?
- Goals
- General features
- Technologies not ported to .NET 7.0
- .NET Releases
Developing a .NET 7.0 Application
The tools for creating, building, and running a .NET 7.0 application are presented, through the use of both the command line and Visual Studio. This module also covers some of the new C# language features that are used by default for the .NET 7.0 code created with Visual Studio, specifically top-level statements, global using directives, and nullable reference types. This module concludes with the details of how to create and use class libraries in .NET 7.0, and the compilation options for building binaries.
- Developing applications for .NET 7.0
- Command line/dotnet.exe
- Visual Studio
- C# default language features
- Top-level statements
- Global using directives
- Nullable reference types
Repository and Unit of Work Patterns
Data access is an essential part of writing any type of application. It is critical that 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
.NET Multi-Platform App UI (MAUI)
This module provides an introduction to .NET MAUI, Microsoft’s latest technology for building cross platform desktop and mobile applications. The basics of creating a .NET MAUI application using Visual Studio and the command line are presented, followed by a detailed discussion of the code and architecture of a .NET MAUI application.
- What is .NET MAUI?
- Architecture
- Supported platforms
- Creating and running a .NET MAUI Application
- Application anatomy
- Folders
- Dependencies
- Files
- Internals
Extensible Application Markup Language (XAML)
XAML is the markup language that is used in .NET MAUI for developing user interfaces. It provides the advantage of being much more declarative, compact and readable than specifying the UI programmatically. This module covers the core syntactic constructs in XAML, such as elements and attributes, type converters, namespaces, markup extensions, layout, and resources.
- XAML Fundamentals
- Syntax
- Property elements
- Markup Extensions
- Properties
- Layout
- Resources
.NET MAUI Data Binding
One of the most interesting features of XAML is its ability to present data quickly and effectively. This module explains the underlying motivation and technology behind associating basic data with the UI. It demonstrates how to connect controls together, how to make business objects “binding-aware”, how to provide type conversions for binding expressions, how to provide visual information for business objects through data templates, and how to manage collections of objects on the UI.
- Data binding fundamentals
- Creating data bindings programmatically
- XAML data binding syntax
- Property element
- Markup extension
- BindingContext
- Reference
- RelativeSource bindings
- INotifyPropertyChanged
- Type converters
- Data templates
- Implementing Master-detail
Model-View-ViewModel (MVVM)
This module discusses the Model-View-ViewModel UI pattern which is useful in separating the UI and visualization from the procedural logic. It looks at how you can use this pattern to structure your application to provide better testability as well as which roles will provide which features (model vs. view vs. viewmodel).
- What is MVVM?
- Architecture
- Model vs. View vs. ViewModel
- What goes where?
- Triggers
- Event Handling
Dependency Injection
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 for a tightly coupled system is 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 use of Microsoft.Extensions.DependencyInjection.
- Dependency Injection in .NET MAUI
- Constructor injection
- Lifetime models: singleton vs. transient
- Creating services and injecting them into the ViewModel
Unit Testing
Testing is a critical aspect of the software development process, and xUnit is the de facto unit testing framework for .NET 7.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 a MAUI ViewModel using manually mocked data.
- Unit testing fundamentals
- Using xUnit with Visual Studio
- Testing code that generates exceptions
- Testing a MAUI ViewModel 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 7.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 ViewModel using xUnit and Moq
This section represents the culmination of all the material covered up to this point in this course. It shows how to use the techniques previously presented to complete the production of a MAUI app that is unit testable and follows modern best practices. It looks at how to use Dependency Injection and the Repository Pattern for writing ViewModels that are easier to test, as well as how to use Moq to make it easier to stub out external dependencies.
- Unit test a ViewModel using xUnit and Moq
Deploying a .NET MAUI Application
After successfully creating, building and testing a .NET MAUI application, the next step is to publish it for production. Publishing a .NET MAUI app for Windows involves creating and installing a MSIX package, which provides modern deployment functionality. This module starts with a discussion of the MSIX package architecture and manifest files, followed by the steps for creating a MSIX package using both Visual Studio and the command line. The module concludes with a demonstration of how to install the app from the MSIX package, and an overview of the publication process for Android.
- MSIX package architecture
- Payload
- Xml files
- Publishing for Windows
- Visual Studio
- Command line
- Installing the app
- Signing with a trusted certificate
- Running the app
- Android deployment
Configuration
Configuration files operate differently in .NET 7.0 from the traditional app.config file from .NET Framework. In a .NET 7.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 a .NET 7.0 application, and the best practice for organizing groups of related settings through the use of the options pattern.
- Initialization and retrieval from a .NET 7.0 configuration file
- Options pattern in .NET
Concurrency
The need for concurrency is driven from three main goals: responsive UIs, scalable computation, and efficient use of compute threads. This section introduces the Task abstraction provided by .NET to allow concurrency to be expressed both in terms of compute and IO. It discusses the issues of thread affinity with regard to UI, and the need to have the maximum amount of concurrency with minimum number of threads.
- How to create units of work to run in parallel, taking advantage of multiple cores
- Efficient use of threads with asynchronous IO
- Using threads with MAUI to maintain a fluid user experience
- The async and await keywords
C# 9.0-11.0
Accompanying the release of .NET 7.0 is a new release of C#. This module presents C# 9.0-11.0, with features that can make code simpler and clearer through the added language support for immutability and compactness.
- Init-only properties
- Record types
- Record structs
- Struct improvements
- Target typing
- Pattern matching improvements
- High performance and interop features
- Coding efficiency features