GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ardalis/Specification: Base class with tests for adding specifications to a DDD model

BranchesTags
Open more actions menu

Latest commit

 

History

515 Commits
515 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
docs
docs
 
 
samples
samples
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
Ardalis.Specification.sln
Ardalis.Specification.sln
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Directory.Packages.props
Directory.Packages.props
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
ci.slnf
ci.slnf
 
 
clean.sh
clean.sh
 
 
coverage.sh
coverage.sh
 
 
exclusion.dic
exclusion.dic
 
 
icon.png
icon.png
 
 
readme-nuget.md
readme-nuget.md
 
 
setup-sqllocaldb.ps1
setup-sqllocaldb.ps1
 
 

Repository files navigation

NuGet Actions Status Generic badge

Follow @ardalis   Follow @fiseni   Follow @nimblepros

Stars Sparkline

Announcement!

Ardalis.Specification is moving to a commercial license. Tell me more

Give a Star! ⭐

If you like or are using this project, please give it a star. Thanks!

Specification

A .NET library for building query specifications. Currently used in Microsoft reference application eShopOnWeb, which is the best place to see it in action, as well as the Clean Architecture solution template. Check out Steve "ardalis" Smith's associated (free!) eBook, Architecting Modern Web Applications with ASP.NET Core and Azure, as well.

Documentation

Read the Documentation

Releases

The change log for version 9 and the list of breaking changes can be found here.

Sample Usage

The Specification pattern pulls query-specific logic out of other places in the application where it currently exists.

  • For applications with minimal abstraction that use EF Core directly, the specification will eliminate Where, Include, Select, and similar expressions from almost all places where they're being used.
  • In applications that abstract database query logic behind a Repository abstraction, the specification will typically eliminate the need for many custom Repository implementation classes as well as custom query methods on Repository implementations. Instead of many different ways to filter and shape data using various methods, the same capability is achieved with a few core methods.

Example implementation in your repository using specifications

public async Task<List<T>> ListAsync(
    ISpecification<T> specification,
    CancellationToken cancellationToken = default)
{
    var query = SpecificationEvaluator.Default
        .GetQuery(_dbContext.Set<T>(), specification);

    return await query.ToListAsync(cancellationToken);
}

Now, to use this method, the calling code simply instantiates and passes the appropriate specification.

var spec = new CustomerByNameSpec("customerName");
var customers = await _repository.ListAsync(spec, cancellationToken);

Specifications should be defined in an easily-discovered location in the application, so developers can easily reuse them. The use of this pattern helps to eliminate many commonly duplicated lambda expressions in applications, reducing bugs associated with this duplication.

We're shipping a built-in repository implementation RepositoryBase, ready to be consumed in your apps. You can use it as a reference and create your own custom repository implementation.

Reference

Please refer to the documentation for related resources.

Pluralsight resources:

  • Design Patterns Library - Specification
  • Domain-Driven Design Fundamentals
  • Specification Pattern in C#

About

Base class with tests for adding specifications to a DDD model

Topics

ddddesign-patternsdomain-driven-designdotnethacktoberfestrepository-patternspecification-pattern

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity

Stars

2.3k stars

Watchers

26 watching

Forks

264 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.