Posts

Showing posts from February, 2025

Measuring the Performance of JSON Alternatives in .NET

Introduction In this post I'll be talking about JSON serialisation performance using the base JSON classes included in .NET ( System.Text.Json ) as well as what used to be the de facto standard for serialisation, and was even included in the .NET templates,  Newtonsoft.Json . I was curious to find out if there were any big differences in performance between the different APIs. For starters, this is the type and instance that we'll be serialising in these examples: public record Data(int Id, string Name, DateTime Timestamp); var data = new Data(1, "Ricardo", DateTime.Now); Lets start first with  Newtonsoft.Json ! Newtonsoft.Json Newtonsoft.Json  has been around for a while, and it was once the default JSON serialiser for .NET, including .NET Framework and .NET Core. It has lots of features, and the new .NET API  System.Text.Json  hasn't (yet) come close to them. It essentially contains two different serialisers/deserialisers: JsonConvert JsonSerializer The way t...

A GitHub Actions Pipeline to Generate OpenAPI Documentation

Image
Introduction This is my first post on GitHub Actions  (GHA), the pipeline part of GitHub (GH), and GitHub Pages (GHP), the static hosting service. I will give an example of a pipeline I built for producing documentation for an OpenAPI spec. Seasoned devops/platform engineering people will probably find this very basic, but I hope it can have interest to someone who is starting to play with GHA! I chose the GitHub products because, essentially, they are available for free, and yet are very powerful. Desired Functionality I would like to: Produce HTML documentation from an OpenAPI specification located in some URL, or from a local file, and make it available somewhere Store each HTML version of the specification independently, e.g., one file for version 1.0.0, another one for 1.0.1, etc Have a template for the documentation, with the ability to add additional contents - header, footer - optionally, as well as insert custom JavaScript and CSS Have the generation run on demand Be abl...

Injecting Action Method Values from Configuration in ASP.NET Core

Introduction ASP.NET Core offers some mechanisms by which it can automatically "inject", or set, values to action method parameters. Normally these come from the query string, the form, the payload, headers, or the Dependency Injection (DI), but the mechanism is extensible, and here we will see a way to inject values from the configuration. We will build: A binding source A model binder provider A model binder An extension method to ease the registration of the model binder provider An "injection" attribute to trigger the injection Model binding in ASP.NET Core is a complex topic and we won't cover it in depth, just what is needed to get this done with a custom model binder . What I'm going to present could probably be done with either a custom value provider or a custom model binder (as in this post), as they are related topics: the former is used to get values from sources and the latter to get them into .NET classes. I will go with model binding for now,...

How I Write Posts

This is a non-technical post, I wanted to explain a few things about my blogging. First, I usually write in British English . This is essentially because I work (and have worked in the past) for British companies, so this is the variant of English that I use daily. This has no other meaning than this. Second, I usually prepare my posts for a long time before they are actually published, but, still, things happen and I sometimes get things wrong, or wish to add/clarify something. So, I frequently make amends to posts, and sometimes I even signal them. My interests include .NET and ASP.NET Core, databases (SQL Server, Elasticsearch ), JavaScript, and web/distributed development in general. I probably won't write about Java, Go, or Python. I tend to avoid what I feel is unnecessary details, such as using directives , and the likes, and also generally keep error handling to the minimum. This doesn't mean that I don't care about it, it's just that it's usually not the po...

Text Querying with EF Core and SQL Server

Introduction SQL Server provides a number of functions that can be used for non-exact text queries over text columns ( CHAR , NCHAR , VARCHAR , NVARCHAR , TEXT , NTEXT ). These include searching a piece of text contained inside another, using full text search, or using patterns, and computing a code from a text. Some of them are: CONTAINS : Searches for precise or fuzzy (less precise) matches to single words and phrases, words within a certain distance of one another, or weighted matches in SQL Server DIFFERENCE : This function returns an integer value measuring the difference between the  SOUNDEX  values of two different character expressions FREETEXT : Is a predicate used in the Transact-SQL WHERE clause of a Transact-SQL SELECT statement to perform a SQL Server full-text search on full-text indexed columns containing character-based data types LIKE : Determines whether a specific character string matches a specified pattern PATINDEX : Returns the startin...

OpenTelemetry with ASP.NET Core

Image
Introduction I wrote a post not too long ago about the building blocks of telemetry , or distributed tracing , with ASP.NET Core. Now I'm going to talk about how we can see it working using an open source bundle, otel-lgtm . Mind you, this may not be 100% suitable for production, but for development purposes, it should be fine, all concepts apply, of course. I won't cover everything about OpenTelemetry here, but should hopefully give you some insights as to what's there and how you can make good use of it. First, lets see what some of the concepts are. If you're interested in learning more about metrics, I suggest having a look at my post on this topic . OpenTelemetry OpenTelemetry  (OTel) provides a single, open-source standard, and a set of technologies to capture and export metrics, traces, and logs from your cloud-native applications and infrastructure. OTel is both a standard and a reference implementation that builds on other standards, such as W3C Distributed Tr...