-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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.
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
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.
Once you have a specification object instance, there are a few things you may do with it.
- You may use it to filter an appropriately-typed
IEnumerable<T>
- You may compose them to form new specifications
- You may match individual objects against the specification
-
(Expressions only) You may use it to filter an appropriately-typed
IQueryable<T>
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.