Myth.Specification 3.0.4-preview.4

This is a prerelease version of Myth.Specification.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Myth.Specification --version 3.0.4-preview.4
                    
NuGet\Install-Package Myth.Specification -Version 3.0.4-preview.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Myth.Specification" Version="3.0.4-preview.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Myth.Specification" Version="3.0.4-preview.4" />
                    
Directory.Packages.props
<PackageReference Include="Myth.Specification" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Myth.Specification --version 3.0.4-preview.4
                    
#r "nuget: Myth.Specification, 3.0.4-preview.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Myth.Specification@3.0.4-preview.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Myth.Specification&version=3.0.4-preview.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Myth.Specification&version=3.0.4-preview.4&prerelease
                    
Install as a Cake Tool

Myth.Specification

NuGet Version NuGet Version

License

pt-br en

It is a .NET library for constructing queries in a very readable way, keeping the business rules in mind.

⭐ Features

  • Easy readability
  • Easy writing
  • Business rules ahead
  • Simplified use

🔮 Usage

To use, the following pattern must be followed:

var spec = SpecBuilder<Entity>
	.Create()
	.And(...)
	.Or(...)
	.Not()
  ...

The main idea is that every bit of your filter is built with the business rule in mind.

Suppose I have a Person table and I need to filter people with a female gender identity, who are from generation Z and who live in city X.

To do this, I should create a static class with the creation of each part of this filter, as follows:

public static class PersonSpecifications {
	public static ISpec<Person> IsGenerationX(this ISpec<Person> spec) {
		return spec.And(person => person.Birthdate.Year >= 2000);
	}

	public static ISpec<Person> IsIdentifiedAsFemale(this ISpec<Person> spec) {
		return spec.And(person => person.Gender == "female");
	}

	public static ISpec<Person> LivesOnCity(this ISpec<Person> spec, string city) {
		return spec.And(person => person.Address.City == city);
	}
}

And then when building my filter, search:

public class PersonService {
	private IPersonRepository _personRepository;

  ...

	public IEnumerable<Person> GetFemalePersonsOfGenerationXOfCityAsync( string city, CancellationToken cancellationToken ) {
		var spec = SpecBuilder<Person>
			.Create()
			.IsGenerationX()
			.IsIdentifiedAsFemale()
			.LivesOnCity(city);

		var result = _repository.SearchAsync(spec, cancellationToken);

		return result;
  }
}

So it's very clear that I'm looking for people with a female gender identity, from generation X and who live in the city I'm looking for.

🪄 Specifications

Specifications can be of three types and worked individually or in groups.

Applying all types can be done as follows:

var enumerable = Enumerable.Empty<Person>();

var spec = SpecBuilder<Person>
	.Create()
	.And(x => x.PersonId != null)
	.Distinct()
	.Order(x => x.Name)
	.Order(x => x.Address)
	.Skip(10)
	.Take(10);

var result = enumerable
	.Specify(spec)
	.ToList();

🔽 Filters

Filters can be applied directly as follows:

var enumerable = Enumerable.Empty<Person>();

var spec = SpecBuilder<Person>
	.Create()
	.And(x => x.PersonId != null);

var result = enumerable
	.Filter(spec)
	.ToList();

The following filters are available:

  • And
  • AndIf
  • Or
  • OrIf
  • Not

⬇️ Ordering

Ordering can be applied directly as follows:

var enumerable = Enumerable.Empty<Person>();

var spec = SpecBuilder<Person>
	.Create()
	.Order(x => x.Name);

var result = enumerable
	.Sort(spec)
	.ToList();

The following orderings are available:

  • Order
  • OrderDescending
  • 📃 Pagination and post processing

Paginations and post processing can be applied directly as follows:

var enumerable = Enumerable.Empty<Person>();

var spec = SpecBuilder<Person>
	.Create()
	.DistinctBy(x => x.Name)
	.Skip(10)
	.Take(10);

var result = enumerable
	.Paginate(spec)
	.ToList();

The following functions are available:

  • Skip
  • Take
  • DistinctBy
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Myth.Specification:

Package Downloads
Myth.Repository

Generic repository pattern interfaces with async support, specification integration, and pagination. Provides read/write separation, CRUD operations, and extensible repository contracts for clean data access architecture.

Myth.Repository.EntityFramework

Entity Framework Core implementations of repository pattern with Unit of Work, specification support, expression handling, and transaction management for robust data access with EF Core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.5-preview.3 37 11/4/2025
3.0.5-preview.2 37 11/4/2025
3.0.5-preview.1 36 11/4/2025
3.0.4 108 11/3/2025
3.0.4-preview.19 48 11/2/2025
3.0.4-preview.17 48 11/1/2025
3.0.4-preview.16 48 11/1/2025
3.0.4-preview.15 58 10/31/2025
3.0.4-preview.14 123 10/31/2025
3.0.4-preview.13 125 10/30/2025
3.0.4-preview.12 118 10/23/2025
3.0.4-preview.11 116 10/23/2025
3.0.4-preview.10 113 10/23/2025
3.0.4-preview.9 112 10/23/2025
3.0.4-preview.8 120 10/22/2025
3.0.4-preview.6 112 10/21/2025
3.0.4-preview.5 112 10/21/2025
3.0.4-preview.4 114 10/20/2025
3.0.4-preview.3 117 10/20/2025
3.0.4-preview.2 35 10/18/2025
3.0.4-preview.1 118 10/7/2025
3.0.3 235 8/30/2025
3.0.2 140 8/23/2025
3.0.2-preview.4 122 8/21/2025
3.0.2-preview.3 97 8/16/2025
3.0.2-preview.1 79 5/23/2025
3.0.1 3,338 3/12/2025
3.0.1-preview.2 156 3/11/2025
3.0.1-preview.1 88 2/5/2025
3.0.0.2-preview 144 12/10/2024
3.0.0.1-preview 182 6/29/2024
3.0.0 4,608 12/10/2024
3.0.0-preview 176 6/28/2024
2.0.0.17 2,328 12/15/2023
2.0.0.16 14,781 12/15/2023
2.0.0.15 294 12/15/2023
2.0.0.11 5,629 8/11/2022
2.0.0.10 2,976 7/20/2022
2.0.0.9 3,080 7/15/2022
2.0.0.8 3,097 7/12/2022
2.0.0.7 3,019 6/20/2022
2.0.0.6 3,138 5/23/2022
2.0.0.5 3,107 5/18/2022
2.0.0 3,188 2/17/2022