Questions tagged [specification-pattern]

Allows business rules to be recombined by chaining the business rules together using boolean logic. The pattern is frequently used in the context of domain-driven design.

114 questions
6
votes
3 answers

Repository and Specification pattern

I'm currently setting up a new project, and I have run into a few things, where I need a little input. This is what i'm considering: I would like a generic repository I don't want to return IQueryable from my repository. I would like to encapsulate…
Luhmann
  • 3,860
  • 26
  • 33
5
votes
3 answers

Specification inside LINQ with EF 4.3

I stumbled trying to use my specification inside a LINQ query. The trouble here is with my specification with params. Let's fake a simple scenario: public class Car { public Guid Id { get; set; } public string Color { get; set; } public…
Kim Tranjan
  • 4,521
  • 3
  • 39
  • 38
5
votes
1 answer

Combining C# code and database code in a Specification

Sometimes you need to define some business rules and the Specification pattern is a useful tool. For example: public class CanBorrowBooksSpec : ISpecification { public bool Satisfies(Customer customer) { return…
cbp
  • 25,252
  • 29
  • 125
  • 205
5
votes
2 answers

EF Core Specification pattern add all column for sorting data with custom specification

I applied Specification Pattern for my .net core project. I also created custom specification for Include, Sorting, Paging etc. I get sort value from api url with queryString and passing to custom specification class. In this class i added some…
TheMuyu
  • 579
  • 2
  • 12
  • 31
5
votes
1 answer

JPA Specification and null parameter in .where clause

I wrote two Specifications which return null if their parameter is null. public static Specification getProdottoByLineaSpec (String linea) { if (linea != null) { return (root, query, criteriaBuilder) -> { …
4javier
  • 481
  • 2
  • 7
  • 22
5
votes
0 answers

How to combine specification pattern with raw sql

I try to implement some application in DDD manner with CQRS. I use asp.net core application, and as well as Microsofts (in the microservices book) I use Mediatr. I want to implement filtering of articles. For that purpose, people advise to use…
Andriy
  • 362
  • 3
  • 16
5
votes
2 answers

Using eager loading with specification pattern

I've implemented the specification pattern with Linq as outlined here https://www.packtpub.com/article/nhibernate-3-using-linq-specifications-data-access-layer I now want to add the ability to eager load and am unsure about the best way to go about…
4
votes
1 answer

How can one define the Selector in ardalis.Specification library?

I am trying to utilize the Ardalis.Specification library to apply the specification pattern in my asp.net 6 project. After installing the library, I created the following specification public class ProductByIdsSpec : Specification
4
votes
1 answer

Type does not satisfy the constraint and incorrectly extends interface when trying to implement generic Specification and Visitor patterns

I'm trying to implement a generic Specification pattern and a generic Visitor pattern together. Here are my base interfaces. export interface Specification> { accept(visitor: TVisitor): void; …
4
votes
1 answer

Exclude null or empty string value from lambda expression

In my app in GetAll function I have a parameter which is called (CustomerModel). I use it to do some filtering over the query and I used specification pattern to avoid using if-else : public async Task>…
peyman gilmour
  • 1,168
  • 2
  • 16
  • 35
4
votes
1 answer

good way to implement NotSpecification: isSpecialCaseOf?

I'm implementing the specification pattern. The NotSpecification seems simple at first: NotSpecification.IsSpecialCaseOf(otherSpecification) return !this.specification.isSpecialCaseOf(otherSpecification) But it doesn't work for all…
koen
  • 13,349
  • 10
  • 46
  • 51
4
votes
2 answers

How to apply multiple filter conditions (simultaneously) on a list?

I have following C# code with .Net 4.0 framework. This is created after referring The Specification Pattern - by Jeff Perrin In the GetProducts() the conditions to be used are defined (hard coded) inside the method. There is another method named…
LCJ
  • 22,196
  • 67
  • 260
  • 418
4
votes
1 answer

PHP specification pattern that allows transformation to sql

I'm trying to find out what the best way would be to have a specification pattern in PHP where the specifications could (optionally) by transformed to PHP. I am exploring some new directions and am testing how well they would work. Code and ideas…
koen
  • 13,349
  • 10
  • 46
  • 51
4
votes
4 answers

Specification Pattern defined in Domain

Using Linq to SQL, and a DDD style Domain Layer with de-coupled repositories, does anyone have any good ideas on how to implement a specification pattern without bleeding L2S concerns up into the domain layer, that is still understandable? :) We…
jlembke
  • 13,217
  • 11
  • 42
  • 56
4
votes
1 answer

Extending LINQ-based Specification Pattern to implement subsumption

There are a lot of LINQ-based implementations of the Composite Specification Pattern. I have not seen one that used Subsumption. Are there any such examples that have been documented (blogs, etc.) or published as open source? I have an idea and…