Skip to content

Generic resource definitions #832

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

Merged
merged 8 commits into from
Sep 18, 2020
Merged

Generic resource definitions #832

merged 8 commits into from
Sep 18, 2020

Conversation

bart-degreed
Copy link
Contributor

Fixes #806.

Made resource definitions a first-class pluggable extensibility point, similar to resource services and repositories. So developers now can derive from JsonApiResourceDefinition, implement IResourceDefinition, or insert base classes in the type hierarchy to share common logic. Such a base class can then be registered as an open generic, so that all resources will use that (unless the container finds a non-generic class, which is a better match) instead of the built-in JsonApiResourceDefinition.

To accomplish this, I had to split up ResourceDefinition into two:

  • JsonApiResourceDefinition is highly pluggable like described above
  • ResourceHooksDefinition contains just the hook callbacks

This way, the recursive resolve logic for resource hooks remains as-is. Since it did not use IResourceDefinitionProvider, that type has been replaced with IResourceDefinitionAccessor, which invokes the requested callbacks directly on the found class. What used to be IResourceDefinition (an internal type to invoke callbacks on) no longer exists.

Additionally replaced IHasMeta with a method on IResourceDefinition and only scan for hook definitions when they are enabled. I intend to update documentation on IHasMeta (which was already wrong) later, as part of #737 (which may change these again).

Bart Koelman added 2 commits September 16, 2020 16:55
Made resource definitions a first-class pluggable extensibility point, similar to resource services and repositories. So developers now can derive from JsonApiResourceDefinition, implement IResourceDefinition, or insert base classes in the type hierarchy to share common logic. Such a base class can then be registered as an open generic, so that all resources will use that (unless the container finds a non-generic class, which is a better match) instead of the built-in JsonApiResourceDefinition.

To accomplish this, I had to split up ResourceDefinition into two:
- JsonApiResourceDefinition is highly pluggable like described above
- ResourceHooksDefinition contains just the hook callbacks

This way, the recursive resolve logic for resource hooks remains as-is. Since it did not use IResourceDefinitionProvider, that type has been replaced with IResourceDefinitionAccessor, which invokes the requested callbacks directly on the found class. What used to be IResourceDefinition (an intermediate type to invoke callbacks on) no longer exists.
Replaced IHasMeta with IResourceDefinition method
@bart-degreed bart-degreed requested a review from maurei September 16, 2020 15:58
Copy link
Member

@maurei maurei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review, will continue later today

@bart-degreed bart-degreed requested a review from maurei September 18, 2020 12:02
@maurei maurei merged commit 9584565 into json-api-dotnet:master Sep 18, 2020
@bart-degreed bart-degreed deleted the generic-resource-definitions branch September 18, 2020 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Generic resource definitions
2 participants