Update README.md

This commit is contained in:
Biarity 2018-01-27 22:20:00 +10:00 committed by GitHub
parent e848b86a16
commit bcd7707e8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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, clean, 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
@ -10,7 +10,7 @@ We'll use Sieve to add sorting, filtering, and pagination capabilities when GET-
### 1. Add required services (`SieveProcessor<TEntity>`)
Inject the `SieveProcessor<TEntity>` service for each entity you'd like to use Sieve with.
So to use Sieve with `Post`s, go to `ConfigureServices` in `Startup.cs` and add:
So to use Sieve with `Post`s, in `ConfigureServices` in `Startup.cs` add:
```
services.AddScoped<SieveProcessor<Post>>();
```
@ -18,7 +18,7 @@ services.AddScoped<SieveProcessor<Post>>();
### 2. Add `Sieve` attributes on properties you'd like to sort/filter in your models
Sieve will only sort/filter properties that have the attribute `[Sieve(CanSort = true, CanFilter = true)]` on them (they don't have to be both true).
So for our `Post` entity model:
So for our `Post` entity model example:
```
public int Id { get; set; }
@ -39,8 +39,8 @@ There is also the `name` parameter that you can use to have a different name for
### 3. Use `SieveModel` in your controllers
In the action handling returning Posts, use the `SieveModel` to get the sort/filter/paginate query.
Apply it by to your data by injecting `SieveProcessor<Post>` into the controller and using its `ApplyAll` method.
In the action handling returning Posts, use `SieveModel` to get the sort/filter/paginate query.
Apply it to your data by injecting `SieveProcessor<Post>` into the controller and using its `ApplyAll` method.
For instance:
```
[HttpGet]
@ -70,7 +70,7 @@ Where `SieveCustomSortMethodsOfPosts` for example is:
```
public class SieveCustomSortMethodsOfPosts : ISieveCustomSortMethods<Post>
{
public IQueryable<Post> Popularity(IQueryable<Post> source, bool useThenBy, bool desc)
public IQueryable<Post> Popularity(IQueryable<Post> source, bool useThenBy, bool desc) // The method is given an indicator of weather to use ThenBy(), and if the query is descending
{
var result = useThenBy ?
((IOrderedQueryable<Post>)source).ThenBy(p => p.LikeCount) :
@ -78,7 +78,7 @@ public class SieveCustomSortMethodsOfPosts : ISieveCustomSortMethods<Post>
.ThenBy(p => p.CommentCount)
.ThenBy(p => p.DateCreated);
return result;
return result; // Must return modified IQueryable<TEntity>
}
}
```
@ -86,12 +86,12 @@ And `SieveCustomFilterMethodsOfPosts`:
```
public class SieveCustomFilterMethodsOfPosts : ISieveCustomFilterMethods<Post>
{
public IQueryable<Post> IsNew(IQueryable<Post> source)
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value) // The method is given the {Operator} & {Value}
{
var result = source.Where(p => p.LikeCount < 100 &&
p.CommentCount < 5);
return result;
return result; // Must return modified IQueryable<TEntity>
}
}
```
@ -101,12 +101,12 @@ Use the [ASP.NET Core options pattern](https://docs.microsoft.com/en-us/aspnet/c
```
services.Configure<SieveOptions>(Configuration.GetSection("Sieve"));
```
Then you can add configuration:
Then you can add the configuration:
```
{
"Sieve": {
"CaseSensitive": `boolean: should property names be case-sensitive? Defaults to false`,
"DefaultPageSize": `number: optional number to trim to when no page argument is given`
"DefaultPageSize": `number: optional number to fallback to when no page argument is given`
}
}
```