Refactoring File System Access

Refactoring File System Access

Years ago, I was trying to test an application I’d written, but couldn’t figure out how to remove a dependency it had on the file system. At the time, I was familiar with unit testing, and had bought into its value both as a developer and as a business owner (this was software that was […]

Refactoring Static System Clock Access

If you have logic that depends on dates and/or times, it can be difficult to test if it’s directly accessing the system clock (via DateTime.Now in .NET, for example). This is an example of an insidious dependency that can add unnecessary coupling to an application, making it harder to maintain. Fortunately, it’s pretty easy to […]

Real World ASPNET Core MVC Filters

Real World ASPNET Core MVC Filters

Filters are a great, often underutilized feature of ASP.NET MVC and ASP.NET Core MVC. They provide a way to hook into the MVC action invocation pipeline, which makes them idealĀ for pulling common repetitive tasks out of your actions. Often, an app will have a standard policy that it applies to how it handles certain conditions, […]

Refactoring Static Config Access

Refactoring Static Config Access

A common but insidious dependency in many .NET applications is their use of configuration, including appSettings. The main issue is static access to config for values that affect the behavior of the application (values that are simply displayed, or used for things like email servers or addresses, aren’t usually an issue). Imagine you have some […]

Enum Alternatives in C#

Enum Alternatives in C#

Some time ago I wrote about Moving Beyond Enums and published an article on ASPAlliance by the same title. Unfortunately the latter article was largely screenshot-based, and those images seem to have disappeared, so I thought I’d revisit the topic here. Enums are simple value-type flags that provide very minimal protection from invalid values and […]

Logging and Using Services in Startup in ASPNET Core Apps

Logging and Using Services in Startup in ASPNET Core Apps

When you set up an ASP.NET Core app, most of the time you begin with the Startup.cs file, which provides essentially three places where you can add code: Constructor ConfigureServices Configure Naturally, the constructor fires first. Then, ConfigureServices is run, and finally the Configure method. You can learn more about this process in my Application […]

The Minimal ASPNET Core App

The Minimal ASPNET Core App

Now updated for ASP.NET Core 1.1 here. There’s no upper limit on how large an ASP.NET Core app can get, but what about how small you can make it? With the new .NET Core framework, the answer is pretty small. Let’s see just how small. First, make sure you have the dotnet CLI tools installed. […]