HttpClient - DelegatingHandler - Correlation Id
Introduction We have multiple microservices in our stack that calls each other. When an error occurs, it's really nice to be able to correlate all the calls to see where something went wrong. Imagine...
View ArticleHow to test configuration of HttpClient when using AddHttpClient
Photo by Caspar Camille Rubin Introduction When you register your custom HttpClient using the AddHttpClient method, it's also quite common that you configure some basic settings like BaseAddress and...
View ArticleUsing embedded files in dotnet core
The problem We want to read a JSON file from disk in our application. We don't want to rely on absolute file paths, hosting environments, copying the files to the output directory etc. The JSON file...
View ArticleGotcha when using Postgres, NodaTime, Ef Core and Dapper
The problem We ran into an interesting bug last week at work. We have a simple ASP.NET Core API that talks to a Postgres database using EF Core (for writes) and Dapper (for reads). The following code...
View ArticleModel bind multiple sources to a single class in ASP.NET Core
The problem We have the following action method: [Route("[controller]")] [ApiController] [Produces("application/json")] public class HomeController : ControllerBase { public IActionResult Post(...
View ArticleUsing records when implementing the builder pattern in C#
Photo by Vitolda Klein I tend to use the builder pattern quite a bit when writing my tests. It's really convinient to create a builder and have a fluent interface when creating some test data. We'll be...
View ArticleC# - Tips and Tricks 01 - Covariant return types
The problem We have the following code: public abstract class MessageHandler { public abstract Message Poll(); } public abstract class Message { protected Message(string id, string correlationId,...
View ArticleC# - Tips and Tricks 02 - Named tuples
The problem We have the following code that returns a tuple. public class UserService { public (string, string) GetUser() { var firstName = "Josef"; var country = "Sweden"; return (firstName, country);...
View ArticleEnumeration class in C# using records
Photo by Alexander Grey Introduction In more or less all projects I worked on over the years, some kind of Enumeration class has always been used. Enumerations (or enum types for short) are a thin...
View ArticleTesting your dotnet applications - Boilerplate
Photo by Roman Mager Introduction This is the first post in the series, Testing your dotnet applications. I will show you how I test my applications and libraries, both ASP.NET and dotnet core...
View ArticleBonus: Builder Pattern with the implicit operator using c#
In a previous post I wrote about using records when implementing the builder pattern. I just had another idea that allows you to skip the .Build call when creating your objects. Example builder:...
View ArticleProtect yourself when deserializing - System.Text.Json
Photo by Pankaj Patel Introduction When dealing with deserialization of JSON, it's always a good idea to validate that it infact deserialized correctly. But, how do you do that using System.Text.Json?...
View ArticleTesting your ASP.NET Core application - using a real database
Photo by Jason Dent Introduction In the previous post we created a weather forecast API that returned hardcoded forecasts. We also created two integration tests that verified that our API returned the...
View ArticleUsing a real Postgres database in your GitHub CI pipeline
The previous post in this series ended with that we made our test project use a real Postgres database. When we pushed our code to GitHub, our action failed (as expected) since the tests could not...
View ArticlePrefix your http requests without touching the actual HttpClient code
I've started to play around a bit with Blazor WASM. I also have an API that's protected with a JWT, and since I want to follow the "no tokens in the browser-policy", I've introduced a BFF (backend for...
View ArticleHow to test configuration of HttpClient when using AddHttpClient
Photo by Caspar Camille Rubin Introduction When you register your custom HttpClient using the AddHttpClient method, it's also quite common that you configure some basic settings like BaseAddress and...
View ArticleUsing embedded files in dotnet core
The problem We want to read a JSON file from disk in our application. We don't want to rely on absolute file paths, hosting environments, copying the files to the output directory etc. The JSON file...
View ArticleGotcha when using Postgres, NodaTime, Ef Core and Dapper
The problem We ran into an interesting bug last week at work. We have a simple ASP.NET Core API that talks to a Postgres database using EF Core (for writes) and Dapper (for reads). The following code...
View ArticleModel bind multiple sources to a single class in ASP.NET Core
The problem We have the following action method: [Route("[controller]")] [ApiController] [Produces("application/json")] public class HomeController : ControllerBase { public IActionResult Post(...
View ArticleUsing records when implementing the builder pattern in C#
Photo by Vitolda Klein I tend to use the builder pattern quite a bit when writing my tests. It's really convinient to create a builder and have a fluent interface when creating some test data. We'll be...
View Article