Posts

ASP.NET Core Distributed Tracing

Image
Introduction Distributed tracing is a technique that allows us to detect failures and performance issues in distributed applications. For example, you send a request to a web app and this web app needs, in turn, to talk to one or more microservices, and possibly some of these microservices need also to talk to others. Distributed tracing is a way to correlate all these calls under the same umbrella. This is usually achieved through special request headers that must be present for distributed tracing to take place. ASP.NET Core offers mechanisms to make our lives easier when working with these headers, which is an implementation of the OpenTelemetry standard.  OpenTelemetry  is an observability framework and toolkit designed to create and manage telemetry data such as traces, metrics, and logs. For now, we'll focus on the building blocks of distributed tracing. You can think of a distributed trace as a transaction with an identifier and many operations, which are ocorring on ...

2024 in Retrospective

This year was very important to me, professionally. I changed job , wrote 18 + 12 posts (in the old and the new blog ) - which, accidentally, means I got a new blog after 15 years with the old one -, went to some cool Microsoft events, and, finally, was awarded as Microsoft MVP once again ! Some things didn't work out exactly as I was expecting them to, but, in general, it was a very positive year. More news coming soon! I'd like to wish you all an excellent 2025!

.NET Cancellation Tokens

Introduction Cancellation tokens in .NET were introduced as part of the  .NET 4 Cancellation Framework . Essentially, it is a standard, cooperative, way to request for the cancellation of the execution of an operation. By cooperative it means that the code that uses it must abide to some rules, as opposed to the cancellation just stopping (killing) the execution. One example of cancellation is, on a web app, when the client closes the connection while the server is performing some long operation. In cases such as this, we may want to abort the operation, as we are not sending the results anywhere (or not, as we shall see). Because of this, ASP.NET Core allows us to add a parameter of type  CancellationToken  to our asynchronous actions, it is automatically associated with the client and is therefore signalled when the client connection is closed. A  CancellationToken  is, essentially, behind the scenes, a ManualResetEvent . Throughout this article I will either ...

What's New in .NET 9 and C# 13

Introduction .NET 9 and C# 13 have been released some days ago , so it's time for my own resume of the new features. There are tons of improvements, quite a few related to performance, so, beware, if you want the whole thing, you should read the official documentation , these are just my personal choices! Semi-Auto Properties C# 13 introduced a new (experimental as of now, you need to turn on the preview language features for the project) keyword called field , which can be used, in auto-properties , to access the auto-generated field.  To set the language version to preview , add this to your .csproj file: <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net9.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <LangVersion>preview</LangVersion> </PropertyGroup> And to make it work: public DateTime Date { get { return field; } ...

MVP Again

Yesterday, December 1st, I was extremely excited to find out that I had been nominated as Microsoft Most Valuable Professional (MVP)  once again! For those of you who are not familiar with this, it is an award granted by Microsoft to some individuals who somehow are relevant to the development community. You can read more about the MVP programme  here . I had previously been an MVP from 2015 until mid 2019, but then I wasn't renewed. This time, my friend and Visual Studio extensions legend Erik Ejlskov Jensen  nominated me, and I was accepted! It is an honour and a privilege to be again part of this exclusive programme, amongst such brilliant people! Besides  Erik , I also need to thank Cristina Gonzalez Herrero , my friend and MVP Community Program Manager for Southern Europe, for reviewing my nomination, and accepting it. Muchas gracias, Cristina! ;-) Please let me know if you want to learn more or discuss this or any other subject. See you around!

Audit Trails in EF Core

Introduction Audit trails is a common feature in database systems. Essentially, it's about knowing, for every table (or some selected ones), who created/updated each record, and when the creates/updates happened. It can also be useful to store the previous values too. Some regulations, such as SOX , require this for compliance. There are some libraries that can do this automatically in EF Core , and there's also the Change Data Capture in SQL Server (and possibly other databases too), of which I wrote about some time ago, but, hey, I wanted to write my own, so here is EFAuditable , my library for doing audit trails in EF Core. This one is designed with some extensibility in mind, so, please, read on. Scenarios EFAuditable  allows the following scenarios: Entities marked for auditing will have the audit columns added and persisted automatically to the database, on the same table Entities marked for history keeping will have their old values (in the case of updates or deletes) ...