Recent Posts

Measure everything - Empty collections

What’s the quickest way to get an empty IEnumerable<string>, List<string>, or string[]? Let’s measure it. The Test As usual, code is running in a Linqpad script and is using Benchmark.Net. #LINQPad optimize+ // Enable compiler optimizations void Main() { Util.AutoScrollResults = true; BenchmarkRunner.Run<EmptyCollectionsBenchmark>(); } [Short...

What’s the quickest way to get an empty IEnumerable<string>, List<string>, or string[]? Let’s measure it. The Test As usual, code is running in a Linqpad script and is using Benchmark.Net. #LINQPad optimize+ // Enable compiler optimizations void Main() { Util....

Customising JSON serialization with Json.Net

While integrating with the API of a popular tropical-sounding online shop, I hit a problem where their Sandbox API was rejecting a perfectly valid request that the main API would most likely be fine with. In this case, it was objecting to decimals being rendered as 10.0 instead of 10, likely because the sandbox is auto-generated from the Swagger models and was just doing a string comparison on...

While integrating with the API of a popular tropical-sounding online shop, I hit a problem where their Sandbox API was rejecting a perfectly valid request that the main API would most likely be fine with. In this case, it was objecting to decimals being rendered as 10.0 instead of 10, likely bec...

Measure everything - Count() vs Any()

Within any community, there are often a series of untested truths. Within development communities, this often takes the form of X is faster than Y or Z is more efficient than W. While these are often true at some point, we don’t often test them to see if they remain true years later. One such instance is Count() vs Any() on IEnumerables and Collections. The general wisdom as I understand it is...

Within any community, there are often a series of untested truths. Within development communities, this often takes the form of X is faster than Y or Z is more efficient than W. While these are often true at some point, we don’t often test them to see if they remain true years later. One such in...

My approach to improving a messy codebase.

In the just over a decade I have been a professional developer, I’ve had to work with alot of messy code, only some of which I wrote. As a result, I’ve spent alot of time refactoring messy code to try and make it in to something better and want to share some of my methods for achieving this. How I approach this has changed over the years but the below are areas I try to focus on and why. The o...

In the just over a decade I have been a professional developer, I’ve had to work with alot of messy code, only some of which I wrote. As a result, I’ve spent alot of time refactoring messy code to try and make it in to something better and want to share some of my methods for achieving this. How...

Handling rate limiting with RestSharp and Polly

I was recently working on an integration with an API that has Rate-Limiting, that is if you go over the permitted number of requests within a certain period of time, you’ll receive a 429 response along with a header telling you how long you need to wait before trying again. I’ve been watching Polly for years but haven’t had the chance to use it, so this seemed like the perfect opportunity and ...

I was recently working on an integration with an API that has Rate-Limiting, that is if you go over the permitted number of requests within a certain period of time, you’ll receive a 429 response along with a header telling you how long you need to wait before trying again. I’ve been watching Po...

Bicep - Create Azure Service Bus with topic and filtered subscription.

It’s been a while since I’ve done anything with Service Bus so to get myself back in to it and indulge my current enjoyment of Bicep, I thought i’d start with creating the service bus, along with a topic, and a filtered subscription, all in Bicep. To start with, the main.bicep which is virtually the same as last time you saw it: param appname string = 'testapp' param environment strin...

It’s been a while since I’ve done anything with Service Bus so to get myself back in to it and indulge my current enjoyment of Bicep, I thought i’d start with creating the service bus, along with a topic, and a filtered subscription, all in Bicep. To start with, the main.bicep which is virtually...

Dependency substitution for legacy code

This post shows an example of how to introduced a form of dependency injection in to legacy code with minimal changes. I refer to this as dependency substitution because, in my view at least, there is a subtle difference between this and depdendency injection. With dependency injection, we are injecting the dependency via either constructor or property injection. The dependency is set once by ...

This post shows an example of how to introduced a form of dependency injection in to legacy code with minimal changes. I refer to this as dependency substitution because, in my view at least, there is a subtle difference between this and depdendency injection. With dependency injection, we are i...

Copying messages between SQS queues

This week I had the need to copy a load of messages from one SQS queue to another, below is the body of the Linqpad script I used to do it. void Main() { var seenIds = new List<string>(); var sidContainer = new DumpContainer("Seen Ids: ").Dump(); var sqsConfig = new AmazonSQSConfig { ServiceURL = "AWS_REGION_URL" }; var client = new AmazonSQSClient("A...

This week I had the need to copy a load of messages from one SQS queue to another, below is the body of the Linqpad script I used to do it. void Main() { var seenIds = new List<string>(); var sidContainer = new DumpContainer("Seen Ids: ").Dump(); var sqsConfig = new Am...

Bicep - Outputting connection string

One of the nice touches of Bicep are some of the helpers it provides you, specifically the environment() helper. This provides information such as Azure endpoints to save you hard-coding it. In my recent journey in to deploying SQL Database, I wanted to output the connection string. Naturally, I did what I do with ARM which is build up the connection string myself, as below: output MyConnecti...

One of the nice touches of Bicep are some of the helpers it provides you, specifically the environment() helper. This provides information such as Azure endpoints to save you hard-coding it. In my recent journey in to deploying SQL Database, I wanted to output the connection string. Naturally, I...

Bicep - A root resource type must have segment length one greater than its resource name

I was working on a Bicep script that would deploy an Azure SQL database server and a database. Below is an excerpt of the file with the relevant pieces: resource server 'Microsoft.Sql/servers@2021-02-01-preview' = { name: 'server${appname}${envtype}' location: resourceGroup().location properties:{ administratorLogin: 'adminuser' administratorLoginPassword...

I was working on a Bicep script that would deploy an Azure SQL database server and a database. Below is an excerpt of the file with the relevant pieces: resource server 'Microsoft.Sql/servers@2021-02-01-preview' = { name: 'server${appname}${envtype}' location: resourceGroup(...