Minimal API growing with .NET 7

To create REST API services with Microsoft .NET, the Minimal API was introduced with .NET 6 - with top-level statements based on some C# 10 features. This was great for very small services, but missed some features which are available with .NET 7. .NET 7 features such as typed results, grouped routes, and filters.

Read More...

Web API Updates with .NET 8

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 investigates the changes coming.

Read More...

Converting Strings to .NET Objects – IParsable and ISpanParsable

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 the Span version of the parse interfaces and using them with generic types.

Read More...

Primary Constructors with C#

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.

Read More...

Calling Web APIs using the dotnet CLI and HTTP Files with Visual Studio

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.

Read More...

System.Text.Json Serializing Hierarchical Data

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.

Read More...

EF Core Mapping with TpH, Generic Types and Value Conversion

EF Core has powerful options to map your domain model to a relational database. In this article, I'll show you how to use the Fluent API to configure a hierarchy of generic classes to map to a single table, and to convert a collection to a store a single string in the database. #dotnet #efcore

Read More...

What’s the SynchronizationContext used for?

Creating Windows applications, UI controls are bound to the UI thread. .NET made it to different iterations with different patterns dealing with asynchronous programming. .NET 4.0 introduced the Task Parallel Library (TPL) and C# 5 added the async and await keywords. Together with these enhancements of .NET, and the synchronization context, invoking methods that make use of different threads has becoming a lot easier.

Read More...

No more Dockerfiles with the help of .NET CLI

This article shows how to use dotnet publish to create a Docker image without using a Dockerfile - including deployment with GitHub Actions.

Read More...

Using MySQL in a Docker container with EF Core

Running MySQL in a Docker container, and accessing it from EF Core

Read More...