Using LocalDB for Integration/Unit Tests

Long did I hold this perception that integration tests are hard. With EF core, they are actually really easy. Instead of using SQL Sever, we can substitute with LocalDB. Run this before running the tests and you'll have your db setup. After calling EnsureCreated you can add things into the database.

Adding custom type converter to MongoDB in C#

I covered how to impelement a custom type converter for MongoDB in my previous article. In this article, I want to cover adding a serializer to MongoDB 'serializer'. There are couple of tricks you can use to make your life easier. Unlike EF Core with its IEntityTypeConfiguration<TType>, MongoDB driver is more static. You can specify ... Read more Adding custom type converter to MongoDB in C#

Custom type converters for MongoDB

I always try to keep my models seperate from the implementation or configuration. EF Core 2.1 added great support for custom type converters with HasConversion. MongoDB also has a support for custom type conversion, though it is not quite as well documented. The basic premise revolves around implementing IBsonSerializer<TType>. Let's suppose I have a Bitrate ... Read more Custom type converters for MongoDB

Clean Architecture in .NET Core 3.0 by Jason Taylor

This video is truly one of the best ones I've ever seen. I am not fully sold on using EF Context everywhere. There are quite a few databases (e.g. MongoDB, ElasticSearch) that do not have an EF Driver. However, since .NET Core has amazing support for integration testing and each handler is nicely isolated, so ... Read more Clean Architecture in .NET Core 3.0 by Jason Taylor

ToByteArrayAsync() - a more 'efficient' approach to converting Streams

Frequently, there is a need to convert a stream into an array of bytes. I came across this problem when uploading files in ASP.NET Core. StackOverflow has certainly a number of answers. In most cases, these answers require copying the array, which is no longer needed. .NET Core 2.0 introduced the concept of Span<T> and ... Read more ToByteArrayAsync() - a more 'efficient' approach to converting Streams

ASP.NET Core - Optimisation Hacks

Google has developed a tool called PageSpeed. It highlighted couple of quick wins I could do to improve website's loading time. Website loading times are one of the most deceptive metrics to measure during development. Website development is frequently done on a local machine when download times are neligiable. It is only once the website ... Read more ASP.NET Core - Optimisation Hacks

ConcurrentDictionary - Get Snapshot and Clear - Fun C# Code #2

Recently, I was asked to write a 'real-time' calculator and the output value was to be stored in Redis. For legacy reasons, it also had to be stored in the database though, only the latest value had to be kept. As the calculator was spewing values, they were stored in a ConcurrentDictionary. When the timer ... Read more ConcurrentDictionary - Get Snapshot and Clear - Fun C# Code #2