Member-only story

Why you should use the Specification pattern in .NET

Bending the Clean Architecture Principles

Anthony Trad
5 min readAug 12, 2022

Introduction

When you work in freelance, you’re exposed to multiple projects with different stacks and constraints in a short period of time. I was recently working on one where I got the inspiration for this post.

At the end of the day, applications are just the implementation of some sort of business rules or process. This process manipulates data and have an output. Applications gets really messy when you you’re implementing and managing those rules on the fly. You can’t just write from scratch every time so you will need a clear, concise and readable way to implement those.

Why the Specification Pattern?

This pattern was formalised by Eric Evans, and Martin Fowler. No introductions needed. The Specification pattern let’s you manage your business rules easily in a flexible way.

It is often used with the Repository Pattern, (I recently wrote an article on Why and When you should not use it so please check it out!) I will not be talking about this use case as it is all over the internet.

Example

Let’s say you are creating a food delivering service. Companies would pay you to get food to their employees upon an order… Pretty simple right?
Companies want to compensate senior and executive positions more than the juniors, so they start throwing…

--

--

Anthony Trad
Anthony Trad

Written by Anthony Trad

Senior Software Engineer focused on .NET and the Cloud. Reconsidering major principles and patterns, ideas are my own.

Responses (1)