Book Image

Adopting .NET 5

By : Hammad Arif, Habib Qureshi
Book Image

Adopting .NET 5

By: Hammad Arif, Habib Qureshi

Overview of this book

.NET 5 is the unification of all .NET technologies in a single framework that can run on all platforms and provide a consistent experience to developers, regardless of the device, operating system (OS), or cloud platform they choose. By updating to .NET 5, you can build software that can quickly adapt to the rapidly changing demands of modern consumers and stay up to date on the latest technology trends in .NET. This book provides a comprehensive overview of all the technologies that will form the future landscape of .NET using practical examples based on real-world scenarios, along with best practices to help you migrate from legacy platforms. You’ll start by learning about Microsoft’s vision and rationale for the unification of the platforms. Then, you’ll cover all the new language enhancements in C# 9. As you advance, you’ll find out how you can align yourself with modern technology trends, focusing on everything from microservices to orchestrated containerized deployments. Finally, you’ll learn how to effectively integrate machine learning in .NET code. By the end of this .NET book, you’ll have gained a thorough understanding of the .NET 5 platform, together with a readiness to adapt to future .NET release cycles, and you’ll be able to make architectural decisions about porting legacy systems and code bases to a newer platform.
Table of Contents (13 chapters)
1
Section 1: Features and Capabilities
4
Section 2: Design and Architecture
7
Section 3: Migration
10
Section 4: Bonus

Types of applications developed using .NET

.NET Core is a versatile framework that can be used to build many types of applications, including the following:

  • Web apps
  • Mobile apps
  • Desktop apps
  • IoT apps
  • Cloud-native services
  • Machine learning

Let's look at each one separately in this section.

Web applications

ASP.NET Core is the main framework for building web applications. It is a core component of the .NET Core ecosystem. Using the MVC architecture helps to build web apps as well as REST APIs. Razor is also a framework part of ASP.NET Core that assists in building dynamic web pages using C# and TypeScript.

Note

WebForms are no longer supported and the recommended alternative is ASP.NET Core Blazor.

Blazor helps in building an interactive client-side web UI using C# instead of JavaScript. It is therefore sharing the server-side and the client-side app logic in .NET, which in certain instances may not be the ideal approach.

In the API domain, besides REST APIs, .NET Core dived deeper into the open source world in communication protocols using a compact and performance-oriented RPC mechanism with gRPC technology. gRPC support is also present in desktop applications, Windows, Linux, and containers. .NET Core also still supports the capability to call the SOAP services via WCF tech, but does not provide hosting as server-side SOAP services. Note that gRPC is now a preferred technology over WCF.

Mobile development

.NET Core also offers mobile application development. The name of the feature set is Xamarin, which is a set of tools and libraries, enabling you to build cross-platform mobile apps. Developers can build native apps for iOS, Android, Windows, and even for macOS.

With .NET 5, Xamarin Forms are convoluted into .NET MAUI, which is open source and present on GitHub at https://github.com/dotnet/maui. With .NET MAUI, development is simplified by providing a single stack that supports all of these platforms: Android, iOS, macOS, and Windows. It provides a single project developer experience that can target multiple platforms and devices.

Desktop applications

With .NET Core 3.0, Microsoft made available the biggest improvements as regards Windows desktop development using Windows Forms and Windows Presentation Foundation (WPF). It also supports the Windows UI XAML Library (WinUI), which was introduced back then along with the Universal Windows Platform (UWP).

New boilerplate WPF or WinForms apps can be simply created using the CLI:

dotnet new wpf
dotnet new winforms p

Internet of Things

Edge computation is increasingly being utilized on a daily basis, from households and water pipes to cars, airplane engines, and what not. .NET Core also provides extensive support for IoT development via Azure infrastructure products, as well as via the UWP framework for IoT devices running Windows 10 IoT Core.

It also offers support for ARM64 on Linux, and ARM64 Docker images are also available. .NET Core has even added GPIO support for the Raspberry Pi.

Cloud-native development and microservices

All of the application deployment types available on Azure are achievable via .NET Core technologies. Various serverless, event streaming, containerization, and many other applications besides are directly supported in cross-platform flavors.

.NET Core fully supports and promotes microservice architecture-based development. It has full support for Windows, as well as Linux Docker containers, to implement microservices and fully adapts Kubernetes as a container orchestrator. It supports and promotes point-to-point communication via the gRPC protocol, as well as out-of-sync communication via various messaging patterns. We will dive deep into these topics in later chapters.

Machine learning

.NET Core provides support to execute machine learning via ML.NET, which is an open source and cross-platform machine learning framework. ML.NET allows you to create custom machine learning models, and train and build them using C# or F# for a number of machine learning scenarios. We will visit this interesting technology in more depth later in this book.

Visual Studio solution templates for .NET

Visual Studio 2019 provides some useful solution templates that generate the boilerplate code for some of the most common application development. They are shown here basically to highlight how straightforward it is to start .NET based development. Note that these solution templates are applicable to both .NET Core and .NET 5.

Here, I will provide you with a quick glimpse into the most popular solution templates for .NET Core-based projects that are readily available with Visual Studio 2019. Note that for all of these solutions, we can easily change the .NET SDK version by going into the project properties. It can be changed for any version of .NET Core and .NET 5 and so on.

Following are the solution templates for the web applications:

Figure 1.1 – Solution templates for web applications

Figure 1.1 – Solution templates for web applications

For desktop applications, we have the following templates:

Figure 1.2 – Solution templates for desktop applications

Figure 1.2 – Solution templates for desktop applications

With this, we can see how easy it is to generate the most popular application types from Visual Studio using .NET Core both for desktop and web application types. Note that in the project properties, you have the option to change the runtime to .NET 5, but the templates still name them as .NET Core.

Next, we will look at the major highlights of the single .NET, in other words, .NET 5.