Skip to content

Commit

Permalink
Updated CustomerSpecExtensions. Added more examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiseni committed Dec 12, 2023
1 parent b11148c commit 924a68c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class AdultCustomersByNameSpec : Specification<Customer>
{
public AdultCustomersByNameSpec(string nameSubstring)
{
Query.Where(c => CustomerPredicates.IsAdult(c) &&
CustomerPredicates.NameIncludes(c, nameSubstring));
Query.IsAdult()
.NameIncludes(nameSubstring);
}
}
11 changes: 10 additions & 1 deletion sample/Ardalis.Sample.Domain/Specs/CustomerSpecExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Ardalis.Sample.Domain.Specs;

// Examples how to add extend specifications.
// Examples how to extend specifications.
// These extensions are applied in Ardalis.Sample.Domain.Specs.CustomerSpec
public static class CustomerSpecExtensions
{
Expand Down Expand Up @@ -33,4 +33,13 @@ public static ISpecificationBuilder<Customer> TagWith(this ISpecificationBuilder
builder.Specification.Items.TryAdd("TagWith", tag);
return builder;
}

// Some more extension examples.
// These extensions are applied in Ardalis.Sample.Domain.Specs.AdultCustomersByNameSpec
public static ISpecificationBuilder<Customer> IsAdult(this ISpecificationBuilder<Customer> builder)
=> builder.Where(x => x.Age >= 18);
public static ISpecificationBuilder<Customer> IsAtLeastYearsOld(this ISpecificationBuilder<Customer> builder, int years)
=> builder.Where(x => x.Age >= years);
public static ISpecificationBuilder<Customer> NameIncludes(this ISpecificationBuilder<Customer> builder, string name)
=> builder.Where(x => x.Name.Contains(name));
}

0 comments on commit 924a68c

Please sign in to comment.