Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< 返回工具列表
S

Specification

> DevOps
开源

Base class with tests for adding specifications to a DDD model

2.3K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Base class with tests for adding specifications to a DDD model

 

 

## Give a Star! :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#

GitHub Issues· 0 开放

在 GitHub 查看全部

暂无开放 Issues,或尚未同步最近议题。

核心特点

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

> 标签

C#ddddesign-patternsdomain-driven-designdotnet

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理