Podcasts are a great way to pass the time when you’re doing chores, doing your daily commute, or even walking the doggo’s. This will be a short post on my part, but I thought it would be worth posting which podcasts I listen to regularly and why. Since this is a technical blog, I’ll stick to the technical podcasts. But each of these are podcasts where I’m always looking forward to the next episode!
While there are really awesome things about both Mac OS and Linux, I’m primarily…
One of the applications that I work with uses PowerShell from with a .NET C# API project. The Nuget package that provides the necessary interfaces is called System.Management.Automation. It is actively maintained by Microsoft, but has API’s that still use the older
IAsyncResult methodology of asynchronous programming, including the
Invoke method on the
PowerShell object itself.
As a result, when trying to add calls to
Invoke within methods that are written as
async/await methods, the fallback was the "good 'ol"
public async Task<bool> IsSessionAliveAsync()
return await Task.Run(() =>
In a project that I’m working on (for the sake of the code samples, this is written using .NET 5 and C# 9), I’m using the fantastic MediatR library by Jimmy Bogard. With this library, I can offload the handing of API requests to handler classes that can be individually dependency injected with just dependencies needed for that one request. I’ve blogged before about using single-endpoint controllers as well. Both options work, but I decided to use MediatR for this project. …
One of the toughest subjects for me to tackle as a professional web developer has been CORS. If you type in “I hate CORS” into Google, you might be surprised at how many results you’ll get (or maybe not…). I get why we use CORS. And it seems simple enough to implement. But, getting it to work properly in my project has been an adventure in frustration to say the least.
The project that I’m working on consists of two repositories. The first is an Angular 12 application for the front-end. The second is a .NET 5 Web API project…
When working with ASP.NET API’s, it’s common practice to have a controller class defined that represents the set of endpoints for a given resource. For example, if your API is working with a Contact resource, the controller will have several endpoints defined, maybe something like the following:
This would be implemented in a class that ultimately derives from
ControllerBase, and would handle each endpoint in its own public method as shown in this example code:
public class ContactController : ControllerBase
private readonly IAppDbContext _dbContext;
public ContactController(IAppDbContext dbContext)…
When writing unit tests in C#, one question that often comes up is how to mock static resources, and which static resources make sense to mock in the first place. I tend to think of this in terms of whether or not the static resource is doing something that I can’t directly control. For instance, I wouldn’t mock
string.IsNullOrEmpty. It's a pure function, meaning that it has no side effects, and given the same input, it will always return the same output. It also doesn't rely on any external data.
Dates area different story.
DateTime.Now is NOT a pure function…
When developing applications with modern frameworks like Angular or React, you often hear about the Redux pattern for managing your global state. I’m not going to go into detail about it here, as it is very widely covered already, but in summary, it’s a data flow pattern that aims to make your code less error prone by way of immutable state.
When your application wants to update some global state (the users profile information, details about whether they’re logged in, etc.), your application will dispatch an action request to the store. The store will respond to this request via a…
For an application that I’m building out with .NET Core and Angular 11, I have the need to query the server at application startup to determine if the application has ever been run before. When the owner of the application uses the site for the first time, the back-end code checks to see if there’s an Administrator account in the system. If not, then it assumes that the application has never been run, and takes the user to a First Run screen. …
Yup, that’s actually a thing! I’ve never personally seen it discussed in any of the talks or presentations that I’ve seen on C# 8, but I ran into a scenario last night where it was useful to have, and managed to track it down on Microsoft’s documentation site, which I’ll link to below.
So, the scenario that sent me searching for a solution, and which led me to this little-discussed operator, was working with the new Nullable Reference Types in C# 8. More specifically, I was setting up an Entity Framework DbContext:
public class ApplicationDbContext : DbContext
It’s been about 15 years since I last stepped foot in a Dojang (Korean for school or training studio), but there was a time that I was very active in that world. Taekwondo practitioners start at what most people know as a white belt, which is known as 8th gup, or 8th level, within the Kukkiwon (the governing body for WTF, or Olympic Style, Taekwondo around the world). …