Multi-targeting your nuget packages
When building a nuget package, you often face the following "dilemma": You want to depend on the lowest possible framework version (to ensure maximum reach), but you also want to take advantage of the...
View ArticleGitOps with GitHub Actions and Argo CD
Lately I've been using GitOps for managing the continous deployment of my applications. My applications runs in a Kuberentes cluster so they are managed by a couple of different yml files (manifests)....
View ArticleUsing http/2 with ASP.NET Core - Traefik/Kubernetes/container example
Intro When dealing with TLS and containers, a common pattern is to terminate the TLS connection in a load balancer and then speak http/1 between the loadbalancer and the container. It has a number of...
View ArticleTesting your Polly policies
Photo by Reuben Introduction We have the following Polly policy: public static IAsyncPolicy<HttpResponseMessage> MyRetryPolicy( int attempts = 3, Func<int, TimeSpan>? sleepDurationProvider...
View ArticleMigrate your database with Entity Framework Core using a separate application
The problem We're using EF Core to handle our database. We're using it to migrate our database schema/data in all our environments. In our dev environments we also use it to seed and clear/reset the...
View ArticleCustomize the HttpClient logging - dotnet core
The problem When doing http calls using the HttpClient, out of the box you'll get the following log output: services.AddHttpClient("my-client", client => { client.BaseAddress = new...
View ArticleStreaming files to Postgres - dotnet core
Well, that's a title I never thought I would write. Anyhow, because of reasons, we're storing files in our database. This post will focus on the storing of the files. The next post will focus on...
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 ArticleStreaming files to Postgres - dotnet core
Well, that's a title I never thought I would write. Anyhow, because of reasons, we're storing files in our database. This post will focus on the storing of the files. The next post will focus on...
View ArticleUsing the X-Forwarded-Prefix header to prefix your HATEOAS links in your API
Scenario All our requests towards our API goes through a BFF (think of it as a proxy). The client calls our BFF and the BFF proxies that call to our API. Now, our API knows nothing about the BFF, it...
View ArticlePrefix IDistributedCache keys
The problem We've multiple applications that share the same Redis cluster. We are using IDistributedCache with Redis as the backing store. Adding an item to the cache looks like this: var cacheKey =...
View ArticleUsing the X-Forwarded-Prefix header to prefix your HATEOAS links in your API
Scenario All our requests towards our API goes through a BFF (think of it as a proxy). The client calls our BFF and the BFF proxies that call to our API. Now, our API knows nothing about the BFF, it...
View ArticleC# - Tips and Tricks 03 - Use static initialization
The problem I often see code like this: public class MyClass { public IReadOnlyCollection<string> MyStrings { get: } public MyClass() { MyStrings = new List<string> { "First", "Second",...
View ArticleAppend correlation id to all log entries in ASP.NET Core
Previously, I used Serilog to append a correlation ID to all my logs, like this: public class LoggingCorrelationIdMiddleware : IMiddleware { private const string CorrelationIdPropertyName =...
View ArticleAct on a Task as soon as it's completed with Task.WhenEach
You have the following code: public async Task RunJobs() { var jobs = Enumerable.Range(1, 20).Select(DoSomeWork); } // Simulates some "real" work private static async Task<(string JobName, TimeSpan...
View ArticleUnsafeAccessor is my new best friend
The problem For reasons I don't want to disclose, I really needed to access a private field in the RedisCache class in the Microsoft.Extensions.Caching.StackExchangeRedis package, namely the _cache...
View ArticleUse the implicit operator to reduce noise in your code
I often use Redis as a distributed cache in my applications. Redis is a key-value store. I prefer to have my cache keys typed; that is, I don't use plain strings throughout my codebase. Instead, I use...
View ArticleKeeping your nuget packages in check
Patch Tuesday / Dependency Day It's important to keep your dependencies up to date, as updates can contain security fixes, bug fixes, new features, and more. Microsoft (and other companies) have...
View ArticleDon't let ASP.NET Core set empty strings to null when posting forms
Recently, I’ve been involved in a project where an old ASP.NET Framework solution has been migrated to ASP.NET Core 8. Today, a bug report was filed: a form that was posted to one of the endpoints...
View ArticleSystem.Text.Json and immutable types - Deserialization
Imagine the following domain object for an Order: public class Order { private HashSet<OrderLine> Lines { get; init; } = []; private Order() { } public required Guid Id { get; init; } public...
View Article