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. Continue reading Minimal API growing with .NET 7

Web API Updates with .NET 8

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. Continue reading Web API Updates with .NET 8

Converting Strings to .NET Objects – IParsable and ISpanParsable

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. Continue reading Converting Strings to .NET Objects – IParsable and ISpanParsable

Primary Constructors with C#

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. Continue reading Primary Constructors with C#

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

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. Continue reading Calling Web APIs using the dotnet CLI and HTTP Files with Visual Studio

<strong>What’s the SynchronizationContext used for?</strong>

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. Continue reading What’s the SynchronizationContext used for?