{"id":29195871,"url":"https://github.com/ignaciocastro0713/specification.lite","last_synced_at":"2026-04-27T17:32:55.751Z","repository":{"id":301948383,"uuid":"1010752701","full_name":"IgnacioCastro0713/Specification.Lite","owner":"IgnacioCastro0713","description":"Specification.Lite is a library for implementing Specification pattern in .NET applications.","archived":false,"fork":false,"pushed_at":"2025-06-29T19:27:55.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-29T19:30:32.134Z","etag":null,"topics":["csharp","dotnet","net8","specification"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IgnacioCastro0713.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-29T18:22:17.000Z","updated_at":"2025-06-29T19:27:59.000Z","dependencies_parsed_at":"2025-06-29T19:31:22.674Z","dependency_job_id":"4b133aca-7a9e-4eb0-bf15-7c2890f8552b","html_url":"https://github.com/IgnacioCastro0713/Specification.Lite","commit_stats":null,"previous_names":["ignaciocastro0713/specification.lite"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/IgnacioCastro0713/Specification.Lite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IgnacioCastro0713%2FSpecification.Lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IgnacioCastro0713%2FSpecification.Lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IgnacioCastro0713%2FSpecification.Lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IgnacioCastro0713%2FSpecification.Lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IgnacioCastro0713","download_url":"https://codeload.github.com/IgnacioCastro0713/Specification.Lite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IgnacioCastro0713%2FSpecification.Lite/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263077629,"owners_count":23410167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","net8","specification"],"created_at":"2025-07-02T05:06:32.830Z","updated_at":"2026-04-27T17:32:55.746Z","avatar_url":"https://github.com/IgnacioCastro0713.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Specification.Lite\n![Release](https://github.com/IgnacioCastro0713/Specification.Lite/actions/workflows/build-release.yml/badge.svg)\n[![NuGet](https://img.shields.io/nuget/dt/Specification.Lite.svg)](https://www.nuget.org/packages/Specification.Lite)\n[![NuGet](https://img.shields.io/nuget/vpre/Specification.Lite.svg)](https://www.nuget.org/packages/Specification.Lite)\n[![GitHub](https://img.shields.io/github/license/IgnacioCastro0713/Specification.Lite?style=flat-square)](https://github.com/IgnacioCastro0713/Specification.Lite/blob/main/LICENSE)\n\n**Specification.Lite** is a lightweight .NET library that streamlines the implementation of the Specification pattern. It helps you encapsulate, reuse, and combine business rules, predicates, and query logic in a flexible and maintainable way.\n\n---\n\n## Features\n\n- **Specification Pattern:**  \n  Define reusable business rules and query logic using strongly-typed specifications. Encapsulate complex predicates into composable objects.\n\n- **Query Extensions:**  \n  Apply specifications directly to `IQueryable` objects for filtering, ordering, and projecting data. Supports asynchronous LINQ operations like `ToListAsync`, `FirstOrDefaultAsync`, `SingleOrDefaultAsync`, and `AnyAsync`.\n\n- **Include Expressions:**  \n  Eagerly load related entities in queries using `Include` and `ThenInclude`, just like in Entity Framework.\n\n- **Ordering:**  \n  Easily apply ordering to queries with `OrderBy` and `OrderByDescending` methods on your specifications.\n\n- **Projection:**  \n  Transform entities to DTOs or other result types within the specification using `Select` and `SelectMany`.\n\n- **Skip \u0026 Take:**  \n  Effortlessly paginate query results using `Skip` and `Take` inside your specifications.\n\n- **Tracking:**  \n  Control whether entities are tracked by the context with `AsTracking`, `AsNoTracking` and `AsNoTrackingWithIdentityResolution` for optimal performance.\n\n- **SplitQuery:**  \n  Enables the use of EF Core’s `AsSplitQuery` to optimize queries containing multiple includes, preventing the cartesian explosion problem.\n\n- **IgnoreQueryFilters:**  \n  Allows you to bypass global query filters (such as soft delete or multi-tenancy) by applying `IgnoreQueryFilters` in your specifications.\n\n- **IgnoreAutoIncludes:**  \n  Prevents Entity Framework Core from automatically applying `Include` statements configured in the model by using `IgnoreAutoIncludes` in your specifications. This gives you full control over which related entities are included in your queries.\n\n- **WithTag:**  \n  Annotate queries with a custom tag using `WithTag` to improve query diagnostics and debugging. This is especially useful for identifying specific queries in logs or performance monitoring tools.\n\n- **Entity Framework Integration:**  \n  Seamlessly integrates with Entity Framework Core, making it easy to use specifications in your repositories or DbContext queries.\n\n---\n\n## Installation\n\nInstall via NuGet Package Manager:\n\n```pwsh\ndotnet add package Specification.Lite --version 1.3.0\n```\nOr add to your project file:\n\n```xml\n\u003cPackageReference Include=\"Specification.Lite\" Version=\"1.3.0\" /\u003e\n```\n\n---\n\n## Usage Examples\n\n### Simple Example\n\nDefine a basic specification and use it to query active users:\n\n```csharp\n// Define a simple specification for active users\npublic class ActiveUsersSpecification : Specification\u003cUser\u003e\n{\n    public ActiveUsersSpecification()\n    {\n        Query\n            .Include(u =\u003e u.Orders)\n            .Where(user =\u003e user.IsActive);\n    }\n}\n\n// Usage in your repository or DbContext\nvar spec = new ActiveUsersSpecification();\nvar activeUsers = await dbContext.Users.WithSpecification(spec).ToListAsync();\n\n// Or directly using the DbContext\nvar activeUsers = await dbContext.Users.ToListAsync(spec);\n```\n\n---\n\n### Complex Example\n\nCombine filtering, includes, ordering, projection, pagination, split queries, ignoring query filters, and no-tracking:\n\n```csharp\n// Complex specification: Get all active users who registered after 2024-01-01,\n// include their orders (with order items), ordered by registration date descending,\n// project to a custom DTO, paginate results, use split queries, ignore global query filters, and return as no-tracking.\n\npublic class RecentActiveUsersWithOrdersSpec : Specification\u003cUser, UserSummaryDto\u003e\n{\n    public RecentActiveUsersWithOrdersSpec(DateTime since, int skip, int take)\n    {\n        Query\n            .TagWith(\"Tag in spec query\")\n            .Where(u =\u003e u.IsActive \u0026\u0026 u.RegisteredAt \u003e= since)\n            .Include(u =\u003e u.Orders)\n                .ThenInclude(o =\u003e o.OrderItems)\n            .OrderByDescending(u =\u003e u.RegisteredAt)\n            .Skip(skip)\n            .Take(take)\n            .AsNoTracking()\n            .AsSplitQuery()\n            .IgnoreQueryFilters()\n            .Select(u =\u003e new UserSummaryDto\n            {\n                Id = u.Id,\n                Name = u.Name,\n                OrderCount = u.Orders.Count,\n                TotalSpent = u.Orders.Sum(o =\u003e o.TotalAmount)\n            });\n    }\n}\n\n// Usage in your application code\nvar spec = new RecentActiveUsersWithOrdersSpec(new DateTime(2024, 1, 1), skip: 20, take: 10);\nvar summaries = await dbContext.Users.WithSpecification(spec).ToListAsync();\n\n// Or directly using the DbContext\nvar summaries = await dbContext.Users.ToListAsync(spec);\n```\n\nSee the [examples folder](./examples).\n\n---\n\n## Contributing\n\nContributions, issues, and feature requests are welcome! or open an issue to get started.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignaciocastro0713%2Fspecification.lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fignaciocastro0713%2Fspecification.lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignaciocastro0713%2Fspecification.lite/lists"}