ASP.NET Core WebHooks - Running the AzureAlertWebHook

Running the ASP.NET Core Webhooks project locally and debugging the AzureAlertWebHook end point.

February 13, 2018 · 3 min

ASP.NET Core WebHooks - Building repository locally

Looking at getting and building the ASP.NET Core Webhooks project on your development machine.

February 11, 2018 · 3 min

Should I use Nullable bool?

TL;DR - no, no, no! Ok, this was a bit blunt, so why shouldn’t you use nullable bools? Let’s start from the beginning … A boolean in .NET is a struct hence is a value type and can not be null. By definition a bool value is either true or false; binary the basic building blocks of computing. Code when written should be clear and through how it is constructed should show intent, I do not believe a Nullable<bool> (or bool?...

January 30, 2018 · 3 min

Are you registering IHttpContextAccessor correctly?

20180918 - Updated the link to HttpServiceCollectionExtensions.cs as the original link no longer worked. Thanks Gareth! After starting to write a service in aspnetcore I needed to access the current HttpContext to get access to the current logged in user. Injecting HttpContext use to be very bad in previous versions of asp.net so I investigated how best to get access to items on it in the new world. This is where I discovered the IHttpContextAccessor interface and a whole new world opened up for me....

January 23, 2018 · 2 min

Why I love Resharper 1

With every new version of C# a new version of Resharper appears. It teaches me the new language features and how I can write my code in the new way. It’s not always right as the code it converts to can be unmaintainable so you have to be careful. But every now and then it makes me realise why I pay for a great productivity tool. public FeatureController(ApplicationDbContext applicationDbContext) { if (applicationDbContext == null) { throw new ArgumentNullException("applicationDbContext", "Argument cannot be null....

January 19, 2018 · 1 min

Missing ClaimsPrincipal in ViewComponents

I was creating a couple of ViewComponents this evening in aspnet core and needed access to the ClaimsPrincipal of the current logged in user. Like the MVC Controller I was expecting the User property of the base class to be a ClaimsPrincipal however I was wrong and it was only a IPrincipal. Was this a bug? Had I missed something? Did I really need to cast User to being a ClaimsPrincipal?...

January 18, 2018 · 1 min

Refactoring Kata - 6 Year Code Review

Going through my old repositories on Github made me realise I’d forgotten about a number of coding items I have done in the past. There was one which was a coding Kata originally created by Scott Allen around refactoring. Refactoring is the ability to improve code readability to increase its simplicity and maintainability. If you write code that the rest of your development team can’t understand or spends 10 times as long to understand before they can alter it then it’s failed....

January 16, 2018 · 6 min

When logic doesn't read well it can lead to confusion

I’ve read a lot of code over the years and I enjoy reading (and contributing to) open source projects. I’ve also read a number of example applications from online learning resources and unfortunately I believe this is where people, who don’t know any better, learn from and learn bad habits. Recently I was watching a course on Pluralsight. Don’t get me wrong the course was great and informative however one of the lines of example code jumped out at me …...

January 9, 2018 · 2 min

Span<T> - byte to int conversions

20180913 update - New post with updated example; enjoy! There has been a recent push for performance improvements in the dotnet framework and as part of that, and any performance improvement work, there has been analysis done around the memory allocations being used for certain operations. I’m probably nearer to novice than expert in this matter however the launch of Span peaked my interest. The main starting point for me was the January 2018 MSDN magazine article by Stephen Toub called C# - All About Span: Exploring a New ....

January 6, 2018 · 3 min

Asp.net MVC Output Caching During Development

During some asp.Net MVC development for a public website recently I have been looking at caching. The content of the site has minimal churn so I looked to use OutputCache. This works fine once it’s been finished and released. However it causes frustrations during development when you want to change something, compile, refresh and nothing happens. One option is to comment out the OutputCache attribute, either on each action or on the specific controller, during development but that seems a bit crazy and isn’t sustainable....

December 13, 2014 · 1 min