Skip to content
Craig Fowler edited this page Mar 5, 2020 · 2 revisions

The NuGet package CSF.Specifications provides a small API for consistent application of the specification pattern. It is usable by .NET Framework (v4.5 and higher) and "netstandard" (v1.0 and higher). This includes all versions of Dotnet Core.

Writing specification classes

To get the most out of this library, you should encapsulate your specification logic within classes. This makes them reusable and avoids duplication. Your specification classes should implement one of the following two interfaces, from the namespace CSF.Specifications.

  • ISpecificationExpression<T> - making it a specification expression class
  • ISpecificationFunction<T> - making it a specification function class

Specification expressions & functions

Where possible, it's best to use specification expressions rather than specification functions. A specification expression is more widely reusable because it can provide both an expression and a function. Filtering IQueryable<T> objects, for example, requires an expression.

The only advantage of specification functions is that they permit completely arbitrary logic.

Using specifications

Once you have a specification object instance, there are a few things you may do with it.

Other info

There are a few other small pieces of functionality in this library.

Also, it might be helpful to read some advice about good practices when using the specification pattern.