Christian Nagel C#
1,411 FOLLOWERS
This is the blog from Christian Nagel and CN innovation with information for developers working with Microsoft technologies including .NET Core, Visual Studio, C#, Microsoft Azure, Universal Windows Platform (UWP), and ASP.NET Core.
Christian Nagel C#
1y ago
To create REST API services with Microsoft .NET, the Minimal API was introduced with .NET 6. The minimal API makes use of top-level statements and is based on some C# language enhancements such as lambda expression improvements such as natural types and declaring a return type. While the minimal API was great for small service implementations, it received some critism with larger applications because with this one source code file was growing too big. With .NET 7, the minimal API offers new features to resolve all these issues as shown in this article.
Minimal API with .NET 6
Let’s start wit ..read more
Christian Nagel C#
1y ago
Preview 3 of .NET 8 includes a new project templates to create an API with a TODO service instead of the weather forecast . Looking into the generated code of this template, there are a lot more changes going on such as a slim builder and using a JSON source generator which helps when using AOT to create native .NET binaries. This article looks into the changes coming.
Todo service instead of weather forecasts
Besides dotnet new webapi which still creates a weather forecast service, a new template is available to create a Todo service. This template is named ASP.NET Core API (the other one i ..read more
Christian Nagel C#
1y ago
A new feature of C# 11 allows abstract static members with interfaces. This makes it possible to define class methods to be used as a contract with a generic class implementation, e.g. using + and – operators. With .NET 7, numeric types implement many new interfaces. This C# 11 feature is not only about math! The new IParsable and ISpanParsable interfaces allow creating objects from strings. As these interfaces can be used with constraints in generic types, parsing strings to create objects is now an easy task with generic implementations. This article shows implementing both the string and t ..read more
Christian Nagel C#
1y ago
To reduce the syntax needed when writing C# code, C# 9 added records with primary constructors. C# 10 then added records for structs. Using C# 12 you can create classes with primary constructors. This article explains the primary constructor syntax and shows the differences between class records, struct records, and normal classes.
Class Records
C# 9 introduced records – with either nominal or positional syntax options. While records add default implementation for equality, with the reduced syntax of positional records because the order of the properties is known, the C# compiler also create ..read more
Christian Nagel C#
1y ago
Visual Studio 2022 17.5 includes new HTTP client tooling. This tool makes it easy to create API calls directly from Visual Studio, with a great output of the API results. It’s easy to directly debug API invocations with this tool. Another tool which I’m using since some years is the HTTP REPL which is available as a dotnet tool. This article shows how both of these tools.
HTTP Repl
A tool I’m already using some years is microsoft.dotnet-httprepl that is available as a .NET tool. To install it globally for the current user, you can use dotnet tool install microsoft.dotnet-httprepl -g.
When th ..read more
Christian Nagel C#
1y ago
The System.Text.Json serializer that was introduced with .NET Core 3.0 gets new features with every new .NET version. With .NET 7, features such as type hieararchies, contract customization, and source generator features have been added. This article shows using the JSON serializer with a hierarchy, and using a source generator.
The Model
The model that’s defined defines the types Game, and Move. The Game class specifies a few simple properties as well as a property of type ICollection that specifies a relationship. Using the primary constructor syntax, the C# compiler creates init-only prop ..read more
Christian Nagel C#
1y ago
The new .NET SDK supports creating Docker images without using Dockerfiles – just by using the .NET CLI – with .NET 7. At this time, it’s just a preview and some features are not yet available, but I had to try it anyway.
This article shows what I had to change with an existing ASP.NET Core Web API project that’s deployed to Azure Container Apps using GitHub actions.
Removing the Dockerfile
The ASP.NET Core application already contains a previously created Dockerfile as shown in the next image. The Dockerfile uses a multi-stage build process to build the application. For building the applica ..read more
Christian Nagel C#
2y ago
Exceptions of type NullReferenceException are the most common errors with .NET applications. With C# 8, nullable reference types have been introduced to get rid of these exceptions. The new .NET 6 and C# 10 project templates turn on nullable reference types. Over the times, many features in regard to nullability have been added to C#! This article shows many of these features.
Nullable Value Types
A value type cannot be null which made it difficult to map it with technologies that allow for optional values, such as the database or XML (nowadays JSON). One way to resolve this is by creating a ..read more
Christian Nagel C#
2y ago
Azure Active Directory B2C (business-to-consumer) is a version of the Azure Active Directory that allows users (consumers) to register with the application.
This article shows how to create an ASP.NET Core application to use this great Azure service.
Creating an ASP.NET Core Web Application
First, let’s create an ASP.NET Core Web application. Using .NET CLI with the ASP.NET Core Web App template, the --auth option gives some different predefined options to authenticate and authorize users:
Individual
IndividualB2C
SingleOrg
MultiOrg
Windows
Using Individual, a local database is created tha ..read more
Christian Nagel C#
2y ago
The new edition of my book is available – covering .NET, C#, WinUI, ASP.NET Core, EF Core, and more! Compared to the previous edition, it not only covers the newest editions of C# and .NET, you don’t have to carry a book with 1500 pages – the number of pages have been reduced – but I made sure that all the important topics are covered, you shouldn’t miss anything important topics needed to develop applications with .NET, C#, and Microsoft Azure.
This book is great for developers moving from other programming languages to C# and .NET, but also for developers already working with .NET to read i ..read more