-
-
Notifications
You must be signed in to change notification settings - Fork 160
Closed
Labels
RFCRequest for comments. These issues have major impact on the direction of the library.Request for comments. These issues have major impact on the direction of the library.enhancement
Description
Description
The ResourceDefinition class exposes developer friendly hooks into how their resources are exposed. It is intended to improve the experience and reduce boilerplate for commonly required features.
As with the prior implementation, the ResourceDefinition will be resolved from the container and can accept any dependencies that have been registered.
Custom Filters
- Introduce
QueryFilterstype which is just an "alias" to Dictionary in an attempt to improve DX
public class QueryFilters
: Dictionary<string, Func<IQueryable<TEntity>, IQueryable<TEntity>>
{ }- The repository becomes responsible for loading the
QueryFiltersand applying them - Any keys present in the
QueryFilterswill not be applied using the default behavior
Example
public class FooResource : ResourceDefinition<Foo>
{
protected override QueryFilters GetQueryFilters() => new QueryFilters {
{ "key1", (query, value) => query.Select(x => x) },
{ "key2", (query, value) => query.Select(x => x) },
};
}
Should be used to handle requests like:
/foos?filter[key1]=value1
Default Sort
Allow a resource to have a default sort if no sort key is provided.
- Introduce
PropertySortOrdertype which is just an "alias" to ReadOnlyList in an attempt to improve DX
public class PropertySortOrder<T>
: ReadOnlyList<(Expression<Func<T, dynamic>>, SortDirection)>
{ }- The repository becomes responsible for applying the default sort if no other sort has been requested
Example
public class FooResource : ResourceDefinition<Foo>
{
public override PropertySortOrder<Foo> DefaultSortOrder = new {
(foo => foo.Bar, SortDirection.Ascending),
(foo => foo.Baz, SortDirection.Descending),
}
}milosloub and joshhubers
Metadata
Metadata
Assignees
Labels
RFCRequest for comments. These issues have major impact on the direction of the library.Request for comments. These issues have major impact on the direction of the library.enhancement