To create custom Specification type, just need to implement ISpecification<T>
interface from FluentSpecification.Abstractions
package.
public class VipCustomerSpecification :
ISpecification<Customer>
{
public bool IsSatisfiedBy(Customer candidate)
{
return candidate
.Comments
.Split(new char[] {';'})
.Contains("Vip");
}
}
Type, prepared in this way can be used with other, built-in Specifications.
var customerSpec = Specification
.NotNull<Customer>()
// Create 'VipCustomerSpecification' by parameterless constructor
.And<Customer, VipCustomerSpecification>();