Skip to content

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