-
-
Notifications
You must be signed in to change notification settings - Fork 158
Query Parameter Services #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… for better extensibility
{ | ||
Expression body; | ||
switch (operation) | ||
{ | ||
case FilterOperations.eq: | ||
case FilterOperation.eq: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency and best practise: use singular words for enums
@@ -197,12 +195,12 @@ private static void AddMvcOptions(MvcOptions options, JsonApiOptions config) | |||
services.AddScoped<IJsonApiReader, JsonApiReader>(); | |||
services.AddScoped<IGenericProcessorFactory, GenericProcessorFactory>(); | |||
services.AddScoped(typeof(GenericProcessor<>)); | |||
services.AddScoped<IQueryAccessor, QueryAccessor>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are fully deprecated in their old forms
/// <summary> | ||
/// A context class that provides extra meta data for a <see cref="TQuery"/> | ||
/// that is used when applying url queries internally. | ||
/// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an entirely new class, merely a refactor of the previously RelatedAttrFilterQuery
and AttributeAttrFilterQuery
src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterParser.cs
Show resolved
Hide resolved
class CurrentRequest : ICurrentRequest | ||
{ | ||
private ContextEntity _contextEntity; | ||
public string BasePath { get; set; } | ||
public List<string> IncludedRelationships { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed things from former request manager that are no longer referenced
@@ -83,9 +80,7 @@ private string GetSelfTopLevelLink(string resourceName) | |||
|
|||
private string GetPageLink(ContextEntity primaryResource, int pageOffset, int pageSize) | |||
{ | |||
var filterQueryComposer = new QueryComposer(); | |||
var filters = filterQueryComposer.Compose(_currentRequest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this as it is incomplete and untested.
We should consider adding |
wiki is clear however it looks like i can only insert one extra paramservice, is this true? how do i add two? would i have: services.AddScoped<IQueryParameterService, TeapotService>();
services.AddScoped<IQueryParameterService, OtherTeaPotService>(); ? |
Closes #562
This PR contains a rework of the internal handling of query parameters. Apart from refactoring, cleaning up and adding unit tests, it contains the following major changes:
These are now discussed below
Decoupled query parameter services
Every supported url query parameter now has an associated dedicated service for parsing it and internally exposing it.
IFilterService
?filter[article.title]=title
IIncludeService
?include=article.author
IPageService
?page[size]=10&page[number]=3
ISortService
?sort=-title
ISparseFieldsService
?fields[article]=title,summary
IOmitDefaultService
?omitDefault=true
guid-value": "00000000-0000-0000-0000-000000000000"
IOmitNullService
?omitNull=false
Throughout the framework, each of these services are now injected only in the places where they are needed. For example: the serialization layer does no longer have access to the filter, sort, page queries.
Migrated responsibilities
As mentioned in the previous part, these dedicated services are responsible for parsing and internally exposing the query parameter. This implies that the following migrations of responsibilities have been introduced
IQueryParser
service is no longer responsible for parsing the url query parameters. The parsing logic for each query has been moved to it's dedicated service (through the implementation of theIQueryParameter
interface).IFilterService
should know how to parse afilter[X]=Y
query stringIQueryParser
is nowIQueryParameterDiscovery
which is only responsible for discovering the registered query parameter services and providing them with the appropriate part of the URL query stringIFilterServices.Parse
method with thefilter[X]=Y
part of the query string.Include
method used to be called with a list of strings (like "article.author.invalid-relationship"), and this list would then be validated and converted into theRelationshipsAttribute
that is actually reflected by that relationship chian. This type of validation now happens directly upon parsing the query parameters in the middlewareBetter extensibility
To register a custom query parameter, all one needs to do is register an implementation of
IQueryParameterService
. See the Query Parameter Services wiki.