Serilog LogContext with StructureMap and SimpleInjector

This article has been updated after feedback from .Net Junkie (Godfather of SimpleInjector). I now have a working SimpleInjector implementation of this, and am very appreciative of him for taking the time to help me :) Serilog is one of the main set of libraries I use on a regular basis, and while it is great at logging, it does cause something in our codebase that I am less happy about....

July 28, 2017 · 4 min

Getting Things Done

I have been trying to actually be productive in my evenings and weekends, but I find I often end up not getting as much done as I feel I could have. I end up browsing imgur, reading slashdot, reddit, twitter, etc. rather than reading books, writing or anything else. The first point doesn’t fit in anywhere else, but somewhere I saw a tip about keeping a house clean (I think):...

July 15, 2017 · 4 min

Terraform, Kinesis Streams, Lambda and IAM problems

I hit an problem the recently with Terraform, when I was trying to hook up a Lambda Trigger to a Kinesis stream. Both the lambda itself, and the stream creation succeeded within Terraform, but the trigger would just stay stuck on “creating…” for at least 5 minutes, before I got bored of waiting and killed the process. Several attempts at doing this had the same issue. The code looked something along the lines of this:...

July 12, 2017 · 2 min

S3 Multi-File upload with Terraform

Hosting a static website with S3 is really easy, especially from terraform: First off, we want a public readable S3 bucket policy, but we want to apply this only to one specific bucket. To achive that we can use Terraform’s template_file data block to merge in a value: { "Version": "2012-10-17", "Statement": [ { "Sid": "PublicReadGetObject", "Effect": "Allow", "Principal": "*", "Action": [ "s3:GetObject" ], "Resource": [ "arn:aws:s3:::${bucket_name}/*" ] } ] } As you can see the interpolation syntax is pretty much the same as how you use variables in terraform itself....

April 23, 2017 · 3 min

Don't write Frameworks, write Libraries

Programmers have a fascination with writing frameworks for some reason. There are many problems with writing frameworks: Opinions Frameworks are opinionated, and will follow their author’s opinions on how things should be done, such as application structure, configuration, and methodology. The problem this gives is that not everyone will agree with the author, or their framework’s opinions. Even if they really like part of how the framework works, they might not like another part, or might not be able to rewrite their application to take advantage of the framework....

April 16, 2017 · 3 min

Using Terraform to setup AWS API-Gateway and Lambda

I have been writing simple webhook type applications using Claudiajs, which in behind the scenes is using Aws’s Lambda and Api Gateway to make things happen, but I really wanted to understand what exactly it was doing for me, and how I could achieve the same results using Terraform. The Lambda Function I started off with a simple NodeJS function, in a file called index.js exports.handler = function(event, context, callback) { callback(null, { statusCode: '200', body: JSON....

March 17, 2017 · 4 min

Unit Tests & Scratchpads

Often when developing something, I have the need to check how a function or library works. For example, I always have to check for this question: Does Directory.ListFiles(".\\temp\\") return a list of filenames, a list of relative filepaths, or a list of rooted filepaths? It returns relative filepaths by the way: Directory.ListFiles(".\\temp\\"); [ ".\temp\NuCrunch.Tests.csproj", ".\temp\packages.config", ".\temp\Scratchpad.cs" ] Now that there is a C# Interactive window in Visual Studio, you can use that to test the output....

January 21, 2017 · 2 min

Update all Docker images

My work’s wifi is much faster than my 4G connection, so periodically I want to update all my docker images on my personal laptop while at work. As I want to just set it going and then forget about it, I use the following one liner to do a docker pull against each image on my local machine: docker images | grep -v REPOSITORY | awk '{print $1}'| xargs -L1 docker pull If you only want to fetch the versions you have the tags for:...

January 16, 2017 · 1 min

MediatR and Magic

Having recently watched Greg Young’s excellent talk on 8 Lines of Code I was thinking about how this kind of thinking applies to the mediator pattern, and specifically the MediatR implementation. I have written about the advantages of CQRS with MediatR before, but having used it for a long time now, there are some parts which cause friction on a regular basis. The problems Discoverability The biggest issue first. You have a controller with the following constructor:...

January 7, 2017 · 3 min

Git Aliases

Git is great, but creating some git aliases is a great way to make your usages even more efficient. To add any of these you can either copy and paste into the [alias] section of your .gitconfig file or run git config --global alias.NAME 'COMMAND' replacing NAME with the alias to use, and COMMAND with what to run. So without further ado, here are the ones I have created and use on a very regular basis....

January 6, 2017 · 2 min