Skip to content

How to create Specification

marektihkan edited this page Sep 13, 2010 · 1 revision

Workflow

  1. Create new class to Core.(BoundedContext).Specifications
  2. Inherit this class from Arc.Domain.Specifications.BaseSpecification<T>
  3. Add expression to Predicate in constructor

Remarks

  • Using Specification in query, it should be translatable to NHibernate criteria

Example


namespace ExampleSolution.Core.Parties.Specifications
{
   public class NameContainsSpecification : BaseSpecification<Person>
   {
       public NameContainsSpecification(string word)
       {
           BuildPredicateFrom(x => x.FullName.Contains(word));
       }
   }
}

var person = new Person("My", "Name");
var containsMyNameInPersonFullName = new NameContainsSpecification("My Name").IsSatisfiedBy(person);