Thread-safety on MemoryCache

Thread-safety on MemoryCache

I have been using the in-memory cache library in a pet project lately and I stumbled on an interesting problem. Are we 100% sure that this class is completely thread safe? Let me clarify a bit. Most of the times, we use a cache as first layer before turning to...

2 minute read
Handling long-running operations in a .NET Background Service

Handling long-running operations in a .NET Background Service

I have seen few articles around about how to execute long-running tasks in a BackgroundService and most of them do the same mistake. The code looks more or less like this: public class MyWorker : BackgroundService { protected override async Task ExecuteAsync(CancellationToken cancellationToken) { while(!cancellationToken.IsCancellationRequested) { await DoSomethingAsync(); } }...

2 minute read
Are design patterns dead? The Singleton problem

Are design patterns dead? The Singleton problem

Today we’ll talk about another Design Pattern: the Singleton. I’m pretty much sure everyone knows what I am talking about, but just to be sure, let’s do a quick recap. The Singleton pattern guarantees that there is only one instance of a class throughout the application. This can be beneficial...

5 minute read
Microservices or Monolith, what to pick?

Microservices or Monolith, what to pick?

Wow, almost 2 months since my last post. I’m really starting to fall behind. And honestly, it would probably have taken even more, if it wasn’t for one of my connections on Linkedin. A few days ago, I got a message from one of my contacts. They wanted a piece...

2 minute read