-
-
Notifications
You must be signed in to change notification settings - Fork 158
Feature request: improved hook support #623
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
Comments
Hi @bart-degreed, thanks again for your input Your first request is an interesting point of discussion. Your concern about server-side paging being skipped completely is valid, but I don't think allowing the query to be executed in the hook itself is the way to address this issue. The main concern here is that To achieve this, An important use-case for such thorough traversal is security: when using hooks to implement Access Control, it ensures that the authorization logic related to every resource will be executed. Nevertheless, server-side paging probably shouldn't be skipped totally. But I don't think there is a trivial answer as to how to approach this best: we could apply the paging before firing the hooks here. But then having authorization as described above will lead to strange behaviour: eg the request page size is I'd like to know more about your particular use-case of the hooks here to figure out what is the best way to approach it: whether to work around the problem (eg paging before executing the queries?) or possibly change the behaviour of [edit]
|
As to your last two points,
and
Thanks for pointing those out. We're aware about the docs: this is still work in progress (#567). We aim to fully update the docs before releasing v4. The issue with that generic implementation of |
I looked into the generic resource definition and realised this is by design: the auto-discovery searches for either
That is why services.AddScoped( typeof(ResourceDefinition<>), typeof(TypeEmbeddedIdResourceHookContainer<>)) We should include this more clearly in the docs, added it to the docs issue. On a side note, if we choose to include that type of registration in the auto-discovery by default, it wouldn't be possible register a resource definition for just a subset of resources, or to use two of such generic resource definitions because one would override the other. So I think it'd be better to not auto-discover unbound resources definitions like that. |
I'd like to be able to register different bindings per resource type, like: User => CustomHookContainer<User>
Group => CustomHookContainer<Group>
Video => TypeEmbeddedIdResourceHookContainer<Video>
Book => TypeEmbeddedIdResourceHookContainer<Book> Maybe the auto-discovery should search for
In my use case, I wanted to update resource IDs based on other property values during GET. We encode IDs to prevent caller guessing values. That works (via OnReturn), unless sparse fieldsets are used. The properties I needed were not always available anymore. For that to work, the invocation needs to move to before Select(). But because I already need a custom service anyway, I decided to put the logic there instead. The reason I need a custom service is that we use Elasticsearch for searching, which returns a list of IDs for the current page. We then enrich the data from SQL Server. So the ordering of get/include/select/sort/page is totally different there. For hooks, I think the following would help:
|
This is still possible by just registering resource definitions explicitly: services.AddScoped<ResourceDefinition<User>, CustomHookContainer<User>>();
services.AddScoped<ResourceDefinition<Group>, CustomHookContainer<Group>>();
services.AddScoped<ResourceDefinition<Video>, TypeEmbeddedIdResourceHookContainer<Video>>();
services.AddScoped<ResourceDefinition<Book>, TypeEmbeddedIdResourceHookContainer<Book>>(); This type of setup is just not auto-discoverable currently, because when multiple unbound types like [edit] Will get back at the other comments shortly |
I tried that (see first post). It does not work. |
That is weird, this should work. I'm using something similar in my projects. Are you calling these explicit registrations after your invocation of (on a side note: autodiscovery should probably check if there already exists a service registration before adding/override an existing one) If that isn't the problem, please provide me with a repro setup so I can look into it. |
As to your other comments regarding Some things that pop up in my mind are:
I will make an effort to draft a proposal soon, but until then any related thoughts are welcome |
Hi All, |
I tried to create a small repro solution based on the latest bits and was unable to reproduce the issue I ran into. I no longer have the original sources, because it turned out that hooks are completely useless to me in their current state. If I run into this again in the future I'll create a separate issue. |
I've been having some thoughts on how to improve the performance of hooks. Elaborates on the last bit of the comment of @mjartz
|
Closing this in favor of #934, which proposes a simpler, non-recursive design. |
Description
The past weeks I have been trying to implement several features of our existing API using JsonApiDotNetCore. Starting out with custom services and repositories, I am now trying to make more use of hooks. One thing that I'm stuck at is the hook support for reading lists.
Consider the next method in
DefaultResourceService
:The first thing to notice is that whenever you start to use a hook (OnReturn in my case), paging no longer works server-side. This is unacceptable for large tables. I think that if the hook subscriber really needs the query executed, it should do so itself and live with the consequences.
Something else I found is that hooks cannot be generic. It's unclear to me if that is a bug or by design. To illustrate, the following works:
but the following does not:
Finally, the documentation on the interfaces in IResourceHookExecutor.cs is wrong. For example, IReadHookExecutor contains: "Wrapper interface for all Before execution methods." Also the file contains the misspelling "appropiate" multiple times.
Environment
Latest commit in develop branch.
The text was updated successfully, but these errors were encountered: