Builder.cs: Dependency Configuration

I can’t take credit for this pattern but some co-workers of mine showed me this and I absolutely fell in love with this pattern. Instead of creating an extensions folder and adding all of the configuration classes and methods.. Why not just create a single class called Builder.cs and put it in the root? I started trying this out on projects and I now find it to be a very good way of organizing dependency injection and configuration. It’s a common pattern that can easily be used across multiple projects.

Builder.cs

Making Builder Methods Extensible Using Actions

This is a very useful trick especially if we’re developing NuGet packages that are being reshared and may need standard configuration with the ability to override.

Here’s a configuration extension for MassTransit that allows overriding default values.