How to defer creation of ODataQueryOptions to repository layer
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Using OData directly on a model in the controller and returning a IQueryable is not an option for many reasons (i.e. access control, no one-to-one fields of DTO to DB, clean architecture, etc). The common option that I found is to have a parameter of type ODataQueryOptions in the controller method and then use the ApplyTo method later.
If you use Clean Architecture a query request in application layer is called that will call the repository. The ApplyTo method will then be called in the repository. This requires that the ODataQueryOptions type needs to be pushed down through all layers and all layers depend on OData.
A better solution would be to just save the OData query that is used in the REST call as a primitive string type and pass it through to the repository. Therfore neither API nor application layers need to depend on OData.
Right now the magic of parsing the query string and creating the ODataQueryOptions type happens in the middleware before the controller. Is it possible to call the parser directly so I can use the query string as a paramater and create the ODataQueryOptions type in the repository?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the middleware parses the REST query string and creates ODataQueryOptions before the controller. Determine whether that parser can be called directly with a primitive query string so repository-layer creation avoids OData dependencies in the API and application layers. Done means a supported approach or a clear explanation of its limitations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100