From 398b246e57edb6a439ba59e8a280ae3f35d2bcbd Mon Sep 17 00:00:00 2001 From: Biarity Date: Sat, 27 Jan 2018 18:33:48 +1000 Subject: [PATCH] Update README.md --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a9da6fe..04a0fd5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # 🎛️ Sieve -Sieve is a simple and extensible framework for .NET Core that adds sorting, filtering, and pagination functionality out of the box. +Sieve is a simple and extensible framework for .NET Core that **adds sorting, filtering, and pagination functionality out of the box**. Most common use case would be for serving ASP.NET Core GET queries. ## Usage for ASP.NET Core @@ -59,10 +59,48 @@ There are also `ApplySorting`, `ApplyFiltering`, and `ApplyPagination` methods. #### Add custom sort/filter methods +If you want to add custom sort/filter methods, inject `ISieveCustomSortMethods` or `ISieveCustomFilterMethods` with the implementation being a class that has custom sort/filter methods for `TEntity`. + +For instance: +``` +services.AddScoped, SieveCustomSortMethodsOfPosts>(); +services.AddScoped, SieveCustomFilterMethodsOfPosts>(); +``` +Where `SieveCustomSortMethodsOfPosts` for example is: +``` +public class SieveCustomSortMethodsOfPosts : ISieveCustomSortMethods +{ + public IQueryable Popularity(IQueryable source, bool useThenBy, bool desc) + { + var result = useThenBy ? + ((IOrderedQueryable)source).ThenBy(p => p.LikeCount) : + source.OrderBy(p => p.LikeCount) + .ThenBy(p => p.CommentCount) + .ThenBy(p => p.DateCreated); + + return result; + } +} +``` +And `SieveCustomFilterMethodsOfPosts`: +``` +public class SieveCustomFilterMethodsOfPosts : ISieveCustomFilterMethods +{ + public IQueryable IsNew(IQueryable source) + { + var result = source.Where(p => p.LikeCount < 100 && + p.CommentCount < 5); + + return result; + } +} +``` + #### Customize Sieve - -## Usage for other than ASP.NET Core - +Use the [ASP.NET Core options pattern](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options) with `SieveOptions` to tell Sieve where to look for configuration. For example: +``` +services.Configure(Configuration.GetSection("Sieve")); +``` ## Send a request