Posts

Introducing ASP.NET HealthChecks.Extensions - Conditional Health Checks

Image
ASP.NET Core offers the Health Checks Middleware , in order to check the health state of your .NET Core API. However is not always desirable to run all the registered Health Checks in every context. For example, in environments like the development one, some dependencies might not be available. Other dependencies might be used later during the application lifetime, maybe when their configuration is finished, or after a feature flag is enabled. Would be nice to decide when to run a health check. One possible way is to write the condition in the Startup  class, as bellow: The Redis health check is added only when the configuration setting has the expected value. If the configuration is changed during the application lifetime, then the only way to re-add the Redis health check is by restarting the API, in order to call again the  ConfigureServices  method. Another good reason to switch on or off a health check is when a feature uses one or maybe more dependencies. If that feature is not y

Verify ILogger calls with Moq.ILogger

Moq is by far the most used mocking library for .NET. It provides objects to either mimic real services implementations or to verify if they were called in a certain way by the Service Under Test. Often teams work hard to have meaningful logs in order to help with investigations, to have the possibility to define alarms based on the content of the logs, or even to help with instrumentation. If there is a log entry that resembles as an exception, then a notification might be sent to a Teams/Slack channel, an email, or even to randomly start the alarms on your team's members' cars (joking, don't do that, you know everyone ignores that Slack channel). There are many situations when an investigation ends up with no resolution, and with a promise to the client that the missing logging lines will soon be added. This it translates into development costs, reputation loss, and maybe most importantly having a missed opportunity to learn about the system's behavior in the p

Invest in learning now!

Image
I worked for several years in a very unique setup with me being the only developer. There was me, the supplier and a guy good with CSS. This supplier had a bunch of small customers, but nothing a developer couldn't handle in a several months span. Also, I couldn't bill more than 5 hours/day in a month, but it was fine, as the rate was good. Being a solo developer comes with some advantages like you get to choose your tools, libraries, frameworks, patterns or technologies and you get to work on all layers. As long as I delivered under the constrained budget and time, the supplier didn't really care how I did it. A big disadvantage was my only available friend when I was in trouble was StackOverflow and often wasn't much. I remember spending days and even nights to solve odd problems when it would have helped to have an experienced colleague to ask or even an extra pair of eyes to look into that missing semicolon. I somehow successfully managed to deliver those solu

Programmer Procrastination

Is when you have to do a quick fix, decide to do it, but refactor something unrelated, then read an article which mentions about Erlang; install the shell, try it, remember about the goroutines and channels concepts in Go; read the wiki for a quick refresh... check the clock, it's 5:00 pm and you don't know how the time passed in the last 3 hours. Let's hope is just a quick fix   (of course I also read the news, saw some random youtube videos, lurked on reddit, but that doesn't sound good, isn't it :) )   The Grape exists and I regret I didn't go there today. Had a great time in the past three weeks.

pseudo brainfuck with the help of C# operator overloading

Linq To Objects Extension: Full Outer Join

Image
I need a report which shows a comparison of the sales of each service with the previous year. Some services might be new and they don't appear in the previous year, others might be put off and so there are no sales for them in the current year. There can be services sold in both periods.

SelectMany - projecting the index of the result

There are 4 overloads of the SelectMany method . Two of them project the index of each source element, for example: string[] sentenceSequences = new string[] {"The quick brown", "fox jumped over","the lazy dog."}; sentenceSequences.SelectMany( // index - the position of the sequence in the sentenceSequences array (sequence, index) => // check if index is on odd position and if so call ToUpper() // ... put the sequence in other array, as the result index % 2 == 0 ? new [] {sequence.ToUpper()} : new [] { sequence } ) .Dump(); But there is no overload for projecting the index of the result also (the index of the element in the result sequence). So here an implementation of it: public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, int, TResult>