-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from furkandeveloper/feature/specification-pat…
…tern ✨ [FEATURE] Ardalis.Specification library has been supported
- Loading branch information
Showing
10 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Ardalis.Specification; | ||
using EasyRepository.Sample.Entities; | ||
|
||
namespace EasyRepository.Sample.Specs | ||
{ | ||
/// <summary> | ||
/// Author By Name specification | ||
/// </summary> | ||
public sealed class AuthorByNameSpec : Specification<Author> | ||
{ | ||
/// <inheritdoc /> | ||
public AuthorByNameSpec(string name) | ||
{ | ||
Query.Where(c => c.Name == name); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
sample/EasyRepository.Sample/Specs/AuthorOrderByNameSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Ardalis.Specification; | ||
using EasyRepository.Sample.Entities; | ||
|
||
namespace EasyRepository.Sample.Specs | ||
{ | ||
/// <summary> | ||
/// Order by author name specification | ||
/// </summary> | ||
public sealed class AuthorOrderByNameSpec : Specification<Author> | ||
{ | ||
/// <inheritdoc /> | ||
public AuthorOrderByNameSpec(string name) | ||
{ | ||
Query.ApplyBaseRules().ApplyByName(name).OrderBy(o => o.Name); | ||
} | ||
} | ||
|
||
public static class AuthorSpecification | ||
{ | ||
public static ISpecificationBuilder<Author> ApplyBaseRules( | ||
this ISpecificationBuilder<Author> specificationBuilder) | ||
{ | ||
specificationBuilder.Include(x => x.Books); | ||
|
||
return specificationBuilder; | ||
} | ||
|
||
public static ISpecificationBuilder<Author> ApplyByName( | ||
this ISpecificationBuilder<Author> specificationBuilder, string name) | ||
{ | ||
specificationBuilder.Where(a => a.Name.Contains(name)); | ||
|
||
return specificationBuilder; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...epository.EFCore.Ardalis.Specification/EasyRepository.EFCore.Ardalis.Specification.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\..\common.props"/> | ||
<PropertyGroup> | ||
<PackageIcon>folders.png</PackageIcon> | ||
<PackageIconUrl/> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="folders.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="6.1.0"/> | ||
</ItemGroup> | ||
</Project> |
31 changes: 31 additions & 0 deletions
31
src/EasyRepository.EFCore.Ardalis.Specification/SpecificationConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Linq; | ||
using Ardalis.Specification; | ||
using Ardalis.Specification.EntityFrameworkCore; | ||
|
||
namespace EasyRepository.EFCore.Ardalis.Specification; | ||
|
||
/// <summary> | ||
/// Specification Builder | ||
/// </summary> | ||
public static class SpecificationConverter | ||
{ | ||
/// <summary> | ||
/// This method convert specification object to queryable object. | ||
/// </summary> | ||
/// <param name="entity"> | ||
/// Entity | ||
/// </param> | ||
/// <param name="specification"> | ||
/// Specification object | ||
/// </param> | ||
/// <typeparam name="TEntity"> | ||
/// Entity | ||
/// </typeparam> | ||
/// <returns> | ||
/// <see cref="IQueryable{TEntity}"/> | ||
/// </returns> | ||
public static IQueryable<TEntity> Convert<TEntity>(IQueryable<TEntity> entity, ISpecification<TEntity> specification) where TEntity : class, new() | ||
{ | ||
return SpecificationEvaluator.Default.GetQuery(entity, specification); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 14 additions & 15 deletions
29
src/EasyRepository.EFCore.Generic/EasyRepository.EFCore.Generic.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\..\common.props" /> | ||
<PropertyGroup> | ||
<PackageIcon>folders.png</PackageIcon> | ||
<PackageIconUrl /> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\EasyRepository.EFCore.Abstractions\EasyRepository.EFCore.Abstractions.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="folders.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<Import Project="..\..\common.props"/> | ||
<PropertyGroup> | ||
<PackageIcon>folders.png</PackageIcon> | ||
<PackageIconUrl/> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\EasyRepository.EFCore.Abstractions\EasyRepository.EFCore.Abstractions.csproj"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="folders.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
</Project> |