Getting started with the Roslyn Analyzers for dotnet
My desk is a mess. There's papers, stickers, spare parts, glasses cleaning cloths, at least one coffee cup, tiny plush toys, and lots of knick knacks and other crap. It is my mess and I know where everything is so it's not a problem... until my wife needs to get something off the desk.
Calling a generic method using reflection
I recently put together a small message queueing system for work. The purpose was to just be able to do some work asynchronously to not block the current call. I didn't feel the need was there for an actual messaging system like MassTransit so I rolled my own. Perhaps that will be a post in the future, but this one mostly is focused on how to call a generic method from a non-generic method passing in a instance of a sub class cast to a base class using reflection.
Use CorrelationId to track calls in ASP.NET 4
But it will help you find the cause. Correlation Id is a value that can for instance be used to track calls in log files as it moves between services. It's a common practice when architecting a system as Microservices, but it's a useful practice in any system that involves calls between services and APIs, since it allows an fairly easy way to group log messages from different logs. It also helps when dealing with systems that span time zones and organizations since the correlation id can be easily passed along in support messages.
Static fields in generic classes
In a new attempt to reboot my blogging I'm putting my exploratory coding sessions in writing (although I'm not sure I can call it reboot, since I'm not sure I booted my blogging to begin with). With exploratory coding I mean that when I come across a question I have, instead of immediately searching for the answer, I try and explore it with code instead. I use LINQPad since it's so fast to get up and running. So over to the question.
Injecting ILogger like all the cool ASP.NET Core kids
Just about every service class used in our ASP.NET Classic sites need a logger. The Nlog way to do that is to put this in your class
C# - Using references as key in Dictionary
A Dictionaryis used to do quick* lookups of a value using a specific key. Any type can be used as both value and key but if you use your own custom type as a key you need to think of a few things.
*Quicker then say a LINQ-query on a list like MyList.Where(x => x.id == id).Single();
The importance of using - well using
In our company, like many others I'm sure, we have a lot of small utility apps filled with legacy code. For us legacy code means code that lacks unit tests, and is full of anti-patterns. Global variables, functions with 100+ lines of code, static classes doing the brunt of the work, and a naming strategy that includes such marvels as MyFunction()
, litter the code. It's very easy to judge the code on these failures, but the code has been in production for many years. It might be held together with staples and duct tape but years of small necessary tweaks means it works well for what they are used for. Occasionally, however, I get reminded of just how fragile this code base is.