Abstract the OS

Abstract the OS

Abstracting the OS - The pain felt of not listening to my own practices.

I'm trying to shift my website to run on a linux app service plan instead of windows. It'll save me $40+ per month, so... worth it. That's 4 extra boxes of booster packs I can get at the end of the year!!!

Anyway... I had to make a code change. Named Semaphore are not allowed on linux.

            if (name != null)
                throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives);

And throw it does.

I normally have the Semaphore wrapped in my Monostate objects, like my HttpClient

public sealed class MonoStateConfig : IConfig
    private static readonly Semaphore s_setOnce = new(1, 1, $"{nameof(MonoStateConfig)} set once");

There was something about me being lazy and not wanting to deal with it. I was alternating between Sync and Async methods; and the versions I've used in the past were annoying me and I wanted to make progress.

While I don't have a lot of monostate objects, I have more than one. I have to go update EVERY SINGLE SEMAPHORE to no longer use the named constructor. Did I get them all? I Don't Know. I can't be sure. I mean... I CAN be because it's my code, all my code.

Normally I can't. But I have to go make changes to multiple files; a large scope of change; because 1 thing is changing.

A single concept has multiple places it has to change due to shifting platforms. Going into Azure, changing from a windows to linux host shouldn't be an outrageous thing. It should all be the same to my code. It's not. Clearly.

There's not a single place I can correct the Semaphore issue. I MUST go change many places.

If I'd wrapped it; created that Abstraction - LIKE I PREFER - single file and fixed everywhere.

BUT NOOOOO..... I didn't. I should. There's a reason I abstract OS components, like HttpClient and Semaphore. It introduces a SINGLE POINT OF TRUTH - a SPOT for changes.

Anyway... that's all I got. Found it amusing that I hit a real world scenario where not following my practice bit my ass.

Show Comments