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

Discovering the distinguishing factors in .NET versions

First of all, the biggest positive point for .NET Core over .NET Framework is that .NET Core is open source. Being open source is a huge plus point as it gets a look-over from critics all over the world as well as providing a lot of valuable feedback and improvements to the open source code. On other hand, .NET Core is newer and was rewritten for cross-platform intentions from the outset, which implies that it is meant to be portable, faster, scalable, and more performant with a lesser memory footprint.

Let's see the core advantages of .NET Framework and .NET Core over one another.

Understanding the advantages of one over the other

Remember that with the advent of .NET Core, .NET Framework is not dead. In the first chapter, we saw the support life cycle for both runtimes and that .NET Framework will still be supported for many years to come. Since it is going to stay, it does have some important aspects that render it preferable to .NET Core under certain conditions.

.NET Core has a heavy focus on microservices and cloud-native application development, and therefore is better in terms of memory and performance when using a containerized form, especially with Docker. .NET Core enables much simpler and smoother usage of side-by-side execution of the same code with different .NET Core versions in addition to its popular self-contained deployment feature.

Let's now have a quick and concise look at the benefits of one runtime over another.

Benefits of using .NET Framework as the main part of your technology stack

Although it sounds odd talking about .NET Framework, version 4.8 was released in 2019, the same year as .NET Core 3.1. Highlighting this reminds us that the tech is new and not irrelevant. Here, therefore, we see the benefits offered by .NET Framework over the other versions:

  • .NET Framework has a very long support cycle compared to .NET Core. As a big enterprise that is not a software company, you do not upgrade your tech stack every 2 or 3 years, which is the case for .NET Core to remain in support.
  • .NET Framework is shipped with Windows and is supported as long as the Windows OS version is supported. This means that the applications do not need to worry about the runtime installations and losing support.
  • If your application is stable and does not require big changes, you are better off upgrading to the latest .NET Framework version and to the latest patch level, as it could be costly to catch up and stay up to date with .NET Core versions.
  • If your existing app or services are using extensive and exclusive features (such as hosting WCF) of .NET Framework, then it is suggested to stay with .NET Framework but upgrade to the latest version. This may lead to a lot of efforts due to the number of changes required.
  • You would need to stay with .NET Framework if your app has a heavy dependency on the use of third-party components or it uses certain NuGet packages that are only available for .NET Framework.
  • If your app uses certain platform-specific features that are not available with .NET Core, then you have no choice to switch until you migrate those platform specific features; or wait until those become available with the latest .NET version.
  • If your app's code is dependent on Code Access Security (CAS), then it will have to stay with .NET Framework because .NET Core does not support it. The CAS feature is not even supported after C# 7.0.
  • There are more and more reference implementations, technical documentation, and resources available for .NET Framework compared to .NET Core.
  • .NET Core often has breaking changes or changes that render previous .NET Core versions obsolete, which means that it would require code changes in order to stay with the latest version, so staying with .NET Framework means fewer code changes.

Benefits of using .NET Core as the main part of your technology stack

Here, we see the benefits of .NET Core compared with other versions:

  • It is a cross-platform technology.
  • It is a container-aware technology.
  • It is rewritten instead of modifying.NET Framework, is built for performance, and has a smaller memory footprint, thereby making it more suited to containers.
  • With this, Entity Framework Core was also introduced, which is better than Entity Framework as it has better support for mappings and query-level performance.
  • .NET Core is shipped independently of Windows and has a clearer and more consistent release cycle.

Initially, .NET Core was built with a focus on server-side applications, but later it evolved into all popular types of applications. However, .NET Core increased its popularity and became a widely adopted framework from .NET Core 3.0. We will now see the additional aspects incorporated by .NET Core 3.0, up to .NET 5, on top of .NET Core.

Benefits of using .NET 5 onward as the main part of your technology stack

Here, we examine the benefits of .NET 5 over other versions:

  • Starting with .NET Core 3, support for WinForms and WPF was included so that the modern Windows desktop apps can be built using .NET Core and .NET 5 has further improved its support.
  • Starting with .NET 5, Xamarin evolved into .NET MAUI, and so now Android, as well as the iOS app, can also be built with the consistent platform and tooling.
  • .NET 5 supports ARM64 Linux flavors, hence the extended support of edge computing for IoT.
  • .NET 5 reduced the memory footprint even further, as well as the disc size, with improvements in app trimming, which has been furthered with container size optimization.
  • .NET 5 introduced C# 9, which added a lot of new features (which we will talk more about in the next chapter).
  • .NET 5 has introduced further performance improvements on top of the already world-class performance by .NET Core 3 in many areas.

In this section, we learned about the main offerings of the specific .NET platform as well as saw the benefits of one over the other and, in particular, what value we can add when we adopt the .NET 5 technology stack. In the next section, we will see why we are working with .NET 5.