Provides a simple implementation of the specification pattern.
dotnet add package Shuttle.Core.SpecificationA custom specification can be implemented by inheriting from the ISpecification<T> interface:
public class MySpecification : ISpecification<MyCandidate>
{
public bool IsSatisfiedBy(MyCandidate candidate)
{
return candidate.IsActive && !candidate.IsDeleted;
}
}A default Specification<T> wrapper class is available that accepts a function as a callback for simple scenarios where an explicit ISpecification<T> implementation may not be warranted:
var specification = new Specification<MyCandidate>(candidate => candidate.IsActive && !candidate.IsDeleted);
if (specification.IsSatisfiedBy(myCandidate))
{
// ...
}An asynchronous specification can be implemented by inheriting from the IAsyncSpecification<T> interface:
public class MyAsyncSpecification : IAsyncSpecification<MyCandidate>
{
public async Task<bool> IsSatisfiedByAsync(MyCandidate candidate)
{
return await _myService.IsActiveAsync(candidate.Id);
}
}A default AsyncSpecification<T> wrapper class is available that accepts a function as a callback for simple scenarios where an explicit IAsyncSpecification<T> implementation may not be warranted:
var specification = new AsyncSpecification<MyCandidate>(async candidate => await _myService.IsActiveAsync(candidate.Id));
if (await specification.IsSatisfiedByAsync(myCandidate))
{
// ...
}