Skip to main content

Posts

Showing posts from 2020

Dependency Injection in ASP.NET Core Attributes

When working with ASP.NET core one of the features now front and centre is dependency injection, built into the framework. Whether you're familiar with the pattern from using an IoC container from an external library, or are new to it with .NET core, the situations where you can't seem to make use of it start to stick out. In the post I'm going to share a few ways of tackling dependency injection with attributes and filters. These require a parameterless constructor and as such you can't use the typical pattern of constructor injection.I've prepared a tiny GitHub repository with the three examples discussed here.1. Using service locationThis first approach will isn't for the purists, and you'll risk other developers muttering "anti-pattern" at you, but it'll work. The idea is to use service location, in the constructor to retrieve the required services and set them to class level variables, where they can be used in the various methods. I…

Recorded Rubber Ducking

Just thought I'd share a "developing in lock-down" tip, which I inadvertently invented (well, let's say discovered) last week. I'm going to call it recorded rubber ducking. The idea of rubber ducking being that if you talk out a problem, even to yourself, you may hit upon the answer.That wasn't working for me, so instead I felt I needed to ask my colleagues to see if someone could see what I couldn't.Importantly though - and really I was just trying not to waste people's time - I took the trouble to clearly write out the issue. What it was, what I'd found, and what still puzzled me. I planned to then post this in Slack, in one hit with all the information, rather than starting with a "@here, anyone know about X?" type of message and follow up from there.And, as you've probably guessed, the act of doing that was sufficient to see the solution to problem* without even bothering anyone.Clearly the action of writing, and forcing me t…

Thoughts on "A Philosophy of Software Design"

I took a recommendation from the blog of Gergely Orosz on a recently released book on software architecture, "A Philosophy of Software Design" by John Ousterhout, purchased and have just finished reading it. In short, I'd second the recommendation - it's not a long book, but is packed with good, practical advice presented from the perspective of an academic, mostly based on his views of many implementations of projects by his students. What I particularly enjoyed about it was that it's a book that makes you think as you go... you aren't simply ticking off a list of things you agree with already. Gergely had a few reservations that he outlined in his post, most of which I also agree with, and I also had some of my own - but all in a postitive way as it made me think and question some practices I've used up to now and consider them from a different viewpoint.In the appendix, John lists 15 design principles that he describes fully in the book, which I'…