Specifications
EventFlow ships with an implementation of the specification pattern which could be used to e.g. make complex business rules easier to read and test.
To use the specification implementation shipped with EventFlow, simply create a
class that inherits from Specification<T>
.
1 2 3 4 5 6 7 8 9 10 |
|
Note that instead of simply returning a bool
to indicate whether or not the
specification is satisfied, this implementation requires a reason (or reasons)
why the specification is not satisfied.
The ISpecification<T>
interface has two methods defined, the traditional
IsSatisfiedBy
as well as WhyIsNotSatisfiedBy
, which returns an
empty enumerable if the specification was indeed satisfied.
1 2 3 4 5 6 |
|
Specifications really become powerful when they are combined. EventFlow also
ships with a series of extension methods for the ISpecification<T>
interface
that allows easy combination of implemented specifications.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
If you need a simple expression to combine with other more complex specifications
you can use the bundled ExpressionSpecification<T>
, which is a specification
wrapper for an expression.
1 2 3 4 |
|
If the specification isn't satisfied, a string representation of the expression is returned.