Redis-based distributed cache in ASP.NET Core

One of the things I particularly like about the new ASP.NET Core is that it’s been designed as a framework with very sensible defaults. The flexibility of rewiring everything the way you like is still there, but the defaults cover what the majority of developers will probably need in most typical scenarios. Also, the definition of the “typical scenario” has significantly changed since the early days of ASP.NET. For instance, caching has always played an important role in web development, but the way we normally cache things today is different than it was 10 years ago.

[Read More]

Null checking, allocations and mass refactoring with ReSharper

Imagine any .NET codebase you have worked on. What would be the most common usage of if statement in this code? Given the notion of The Billion Dollar Mistake, I bet it is the null check. Reference types in .NET are allocated on the managed heap, so when an instance of such a type is assigned to a variable, this variable essentially points to an adress in this managed heap. The default value of such a variable is null, meaning that it points to nothing and can’t be dereferenced. For instance, if you write a method with a reference type argument, you can’t always predict how this method is going to be invoked and there is no guarantee that it won’t be a null value. To protect your code from an unexpected NullReferenceException, you would typically write something like this:

[Read More]

5 Ways To Manage Database Schema Changes in .NET

Most useful applications these days store some data in some storage. Sometimes this storage is a relational database with a well-defined schema. This schema might evolve with time, requiring production databases to be updated. In some cases, this is a rare occasion and perhaps can be done manually. However, if a company follows an agile approach and is trying to deliver new releases continuously, then these manual updates can quickly become too much of a headache even for experienced DBAs.

[Read More]

C# 7.0: Deconstruction demystified


Let’s talk about one of the cool new features of C# 7.0 - deconstruction. Quite often you might need to return more than one value from a method, which can be accomplished in several ways:

  • use out/ref arguments (usually considered a code smell)
  • create a more meaningful class/struct that represents the result of calling the method (a preferable option, especially as the number of returned values grows)
  • use System.Tuple (some kind of a middleground)

They all work, but in fact only a special return type feels like a good solution, since both out arguments and explicitly used tuples look just like a boilerplate code and don’t contribute to readable code.

[Read More]

Abusing .NET Core CLI

When developing with .NET Core, you have two different workflows to choose from: manage projects from Visual Studio or work from a command-line using dotnet commands. New projects can be created this way, and after the recent updates the project templates system became extensible, allowing to install additional templates or even create your own.

[Read More]