Title: Streamline API surface by csantero · Pull Request #62 · JSONAPIdotNET/JSONAPI.NET · GitHub
Open Graph Title: Streamline API surface by csantero · Pull Request #62 · JSONAPIdotNET/JSONAPI.NET
X Title: Streamline API surface by csantero · Pull Request #62 · JSONAPIdotNET/JSONAPI.NET
Description: This is the first part of a refactor that I hope will make our library even simpler to setup. Rationale There are starting to become a lot of moving parts that the user has to configure to get JSONAPI.NET integrated with their project: IPluralizationService IModelManager JsonApiFormatter EnableFilteringAttribute EnableSortingAttribute EnumerateQueryableAsyncAttribute PascalizedControllerSelector ApiController-derived classes IMaterializer A lot of those components only fit together in one way, and trying to change their behavior will just break the system. For example, if you want filtering and sorting, you better remember to pass the same IModelManager instance to each of the attributes, as well as to the JsonApiFormatter. And the action filters have to be registered in the right order, since filtering should be applied before sorting (and when we introduce paging, it absolutely must take place after sorting). And then there is the async enumerator, which has to run after all the other action filters. I felt like I could internalize a lot of stuff and only expose a simple API with sensible defaults that does all of that for you. JsonApiConfiguration There is now a fluent interface for configuring JSONAPI.NET called JsonApiConfiguration. This object is responsible for setting up an HttpConfiguration object the way we need it. The user can currently use this fluent interface to disable sorting and/or filtering, and to provide a pluralization service. It also lets them opt-in to the async queryable enumerator using a fluent extension method. JsonApiQueryableAttribute I have combined the functionality of the filtering and sorting action filters into a new aggregate attribute called JsonApiQueryableAttribute. I abstracted the old filters into new constructs called IQueryableTransforms, and I pass those transforms to the JsonApiQueryableAttribute inside JsonApiConfiguration.Apply(). When we implement pagination we can make that an IQueryableTransform as well. Autofac I've taken on Autofac as a library dependency, and JsonApiConfiguration uses it internally to manage the construction of our various components (JsonApiFormatter, ModelManager, JsonApiQueryableAttribute, etc.). At the moment the container I use for this purpose is not integrated with the HttpConfiguration's dependency resolver and will not interfere with controller instance DI. Still to do The JsonApiFormatter can be cleaned up to be internal and use a single constructor. If we want to inject our own services onto controller instances (such as IMetadataManager), then I believe we will need to take over setting the IDependencyResolver. If we do this, however, we will be forcing the user to use Autofac for resolving controller dependencies, which sounds pretty heavy-handed. At the very least we'd have to give them access to the ContainerBuilder for customization. ModelManager and IModelManager can be made internal. PascalizedControllerSelector can be made internal. Some links Example JsonApiConfiguration JsonApiConfiguration definition
Open Graph Description: This is the first part of a refactor that I hope will make our library even simpler to setup. Rationale There are starting to become a lot of moving parts that the user has to configure to get JSON...
X Description: This is the first part of a refactor that I hope will make our library even simpler to setup. Rationale There are starting to become a lot of moving parts that the user has to configure to get JSON...
Opengraph URL: https://github.com/JSONAPIdotNET/JSONAPI.NET/pull/62
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1e19365a-eb41-906a-630c-c0d72f399a7a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A68A:877A:3E65C4:530C51:6A52D0DF |
| html-safe-nonce | 2b11d1cfb93a9d83f4ed1a20bcfaff30405b492ae786f05988e14c0bfc07b3b9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjhBOjg3N0E6M0U2NUM0OjUzMEM1MTo2QTUyRDBERiIsInZpc2l0b3JfaWQiOiI5MDM1ODk3Nzg5OTEwMDEyMTI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bb7ad7f733cf0f9fe9365e89d53b6ae7f16a64dc0f097b32cb2a94bf6af447a0 |
| hovercard-subject-tag | pull_request:29225905 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/JSONAPIdotNET/JSONAPI.NET/pull/62/files |
| twitter:image | https://avatars.githubusercontent.com/u/828286?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/828286?s=400&v=4 |
| og:image:alt | This is the first part of a refactor that I hope will make our library even simpler to setup. Rationale There are starting to become a lot of moving parts that the user has to configure to get JSON... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/JSONAPIdotNET/JSONAPI.NET git https://github.com/JSONAPIdotNET/JSONAPI.NET.git |
| octolytics-dimension-user_id | 16112275 |
| octolytics-dimension-user_login | JSONAPIdotNET |
| octolytics-dimension-repository_id | 27474358 |
| octolytics-dimension-repository_nwo | JSONAPIdotNET/JSONAPI.NET |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27474358 |
| octolytics-dimension-repository_network_root_nwo | JSONAPIdotNET/JSONAPI.NET |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width