Skip to content

HuddleEng/Specification

Repository files navigation

Specification pattern

This code is base on Eric Evans and Martin Fowler's article introducing the Specification pattern

Simple example in the tests can be found here UserPreviouslyActiveIsPartOfTheRecentlyInactiveCohort.cs

ISpecification<UserContext> inactiveCohort =
                new UserIsInactiveForOverTwoWeeks()
                .And(new UserHasViewedSomeThing())
                .And(new UserHasUploadedSomeThing())
                .And(new UserHasNotReceivedAReportThisMonth());

var userContext = new UserContext
{
    LastActiveDate = DateTime.UtcNow.AddDays(-15),
    LastReportSent = DateTime.UtcNow.AddMonths(-1),
    TotalUploads = 10,
    TotalViews = 50
};

bool userInCohort = inactiveCohort.IsSatisfiedBy(userContext)

In this series

  1. All about security
  2. The power of Composite Specifications
  3. Specifications 3: The DSL Strikes Back
  4. Knock knock. Who's there? AbstractSpecificationNodeVisitorImpl

About

C# implementation of the specification pattern

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages