From .NET in Action, Second Edition by Dustin Metzgar
This book offers a clear-headed introduction to implementing full-featured, cross-platform professional applications on the Microsoft .NET platform.
Read on if you’re curious about .NET.
There has never been a better time to be a .NET developer. .NET runs on almost everything: from embedded devices and sensors to game engines like Unity and Godot, from mobile devices to all major clouds. The skills you’ll learn from this book apply across the broad .NET ecosystem. This book covers the necessary foundation and gets you building production-ready applications.
.NET looks a lot different now than it did in 2002 when I was first starting working with it professionally. Features were introduced, improved, and sometimes replaced or deprecated but still supported. Microsoft maintained backward-compatibility with each version of the .NET Framework to prevent breaking existing applications. This was great for customers but resulted in the accumulation of some “baggage” over the past 20 years.
The first edition of this book, .NET Core in Action, explored how Microsoft decided to “hit refresh” and begin anew. They mixed the best parts of .NET with some new ideas and modern techniques to create .NET Core. Having different .NET’s, like Framework and Core (and Standard), caused some confusion and Core was clearly the future. So Microsoft decided to drop the “Core” and just go with .NET when they released .NET 5 (5 being greater than .NET Core 3.0 and .NET Framework 4.8). In .NET 6 and 7, we’re now seeing an evolution. Whether you’re new to .NET or an experienced veteran, this is an exciting time to be a .NET developer.
Where is .NET used?
ASP.NET Core is .NET’s web framework. It can be hosted in either a lightweight server called Kestrel or in the Windows Internet Information Services (IIS) host. Kestrel enables ASP.NET Core to run on containers, which makes ASP.NET Core perfect for microservices. There are a number of hosting services available in cloud providers that either use the container model, IIS, or serverless options.
.NET is also used in desktop (i.e. thick client) applications. There are many options to choose from. Traditional Windows Forms applications are available, which is helpful for maintaining older applications. Windows Presentation Foundation (WPF) has an XML-based approach and is widely used for desktop applications.
You can also write .NET applications with WinUI. This gives you access to PC, tablet, Xbox, and Hololens. WinUI makes it easier to interact with touch, pen, and game controller input as well as mouse and keyboard. To write iOS, macOS, and Android applications, use Xamarin or the new Multi-platform App UI (MAUI), which is an evolution of Xamarin.
If you’re interested in small devices, sensors, and micro-controllers, there are many opportunities to use .NET. For instance, .NET runs on boards like the Raspberry Pi and the Hummingboard. The .NET IoT (Internet of Things) community maintains a set of components for device bindings to work with specific hardware. These are things such as LCDs, temperature sensors, and analog-to-digital converters. If the hardware is too small to run .NET 6, there are “lighter” implementations like the .NET nanoFramework and Meadow, which work on embedded devices.
.NET in the job market
Stack Overflow (which is built with .NET) holds an annual developer survey to learn about all facets of development from geography and years in industry to the most loved or dreaded frameworks. In the 2021 survey, .NET is mentioned in a few key areas:
- .NET Core / .NET 5 is the most loved framework and the 2nd highest paying
- ASP.NET Core is the 2nd most loved web framework, losing only by a small percentage but with 7 times as many votes as the #1 web framework
- ASP.NET Core also ranked as the 3rd highest paying web framework
- F# ranked as the 2nd highest-paying programming language
There is a lot of information in the report and it’s worth a read. You can find each year’s report here: https://insights.stackoverflow.com/survey
When to use .NET
At one time, .NET was a Windows-only framework. This hasn’t been true for years. .NET works on Windows, Linux, and Mac for desktop applications as well as Android and iOS for phone and tablet. .NET is used in microcontrollers, IoT devices, and games. You can even use .NET in shell scripting via PowerShell. But the bulk of jobs in .NET will be for web services and applications.
Whether or not you should use .NET depends on your scenario. Here is a list of scenarios where .NET is an option but not commonly used.
- Data science – While some strides have been made in using .NET for data science and machine learning, it would be better to start with Python.
- Hardware drivers – Managed code in hardware drivers could be useful in that the code is safer and easier to write. However, it requires an understanding of garbage collection, JIT/AOT compilation, and trimming. A language like Rust may be a better starting point.
- Games – Game developers using an engine like Unity or Godot can use C# in their scripts. There are books and tutorials specifically covering C# for these use cases that would be more targeted than this book. .NET has been used in the past to write entire games but this book doesn’t explore those frameworks.
This is not to say that .NET cannot be used in these scenarios. Choosing what language/framework to use depends on many factors, such as performance, security, what the development team is comfortable with, what support is available, and how big (and welcoming) the community is. .NET has 20 years of hardening and improvements plus millions of active developers. It is open source with a large and engaged community. .NET has strong support from Microsoft, even without the support contracts that many companies already have.
What will I learn from this book?
This book aims at two types of developer: (1) those that are familiar with other programming languages and are new to .NET and (2) those that have previous .NET experience but are looking to catch up with the latest. If you’re new to programming in general, this book may be difficult to follow. I assume you have a general idea of the following concepts:
- Software patterns – Some basic patterns are used in this book such as Singleton, MVC, and method-chaining. A lot of these patterns are well-known so the book only does a brief introduction. It’s generally important to know what software patterns are as they provide a language for communicating with other software developers.
- Web services and web applications – If you know about URLs, HTTP, requests, responses, and web servers then you should be able to follow the examples.
- Terminal usage – The examples in this book provide instructions that are executed in the terminal (command line in Windows). If you’re using an IDE like Visual Studio or Rider, you may need to look up how to translate those commands into actions in the UI or just have a terminal open along with your IDE.
Developers that have used .NET in the past will get acquainted with all the new bells and whistles. A lot has changed in .NET and you may be surprised at the changes. Here are some relatively new concepts as of .NET 6 that are covered in the first three chapters:
- Top-level statements
- Nullable reference types, null coalescing, and other null operators
- Global and implicit usings
- dotnet watch and Hot Reload
As you read the table of contents for this book, you may wonder how everything fits together. Figure 1 shows how these topics align. Early in the book, we’re building an understanding of the CoreCLR and the services it offers. On top of that, we’ll learn C# throughout the first few chapters. The class libraries available in CoreFX are essential to understand what is available in .NET and what has to be pulled in via external packages.
Figure 1. High level diagram of how topics covered in the book fit together
The dashed boxes arranged vertically indicate cross-cutting concerns. For example, performance is a subject that impacts everything from understanding how the JIT compiler impacts your application to how to use ASP.NET Core more efficiently. While there are several areas that involve ASP.NET Core, such as security and fault-handling, this book is focused on .NET in general and not intended to be a comprehensive reference on ASP.NET Core.
By the end of this book, you should be able to author and deploy libraries, console applications, web services, and web applications. Your applications will be able to store and manipulate data in databases and through other services. You will have an intermediate-level understanding of important .NET concepts and features. My goal with this book is to quickly get you to the point where you can develop .NET applications professionally. It’s definitely possible to dive deeper into many of the subjects introduced here and there are other books available from Manning that will help you do that.
You can learn more about the book here.