Description
DESCRIPTION
Context. I was trying to leverage resource hooks to implement dynamic, role-based authorization for resources. For example, the API should only return a subset of resources (e.g., Document
) to which the authenticated user has been granted read access (Update 2021-05-12: based on @bart-degreed's feedback on resource hooks, I then played with resource services for the same purpose).
Issue. I've tried to mimic the JsonApiDotNetCoreExample in my solution. However, my resource hooks definition, which is derived from ResourceHooksDefinition<Document>
(Update 2021-05-12: but not in the same assembly as the Document
resource), is not registered by the following call:
services.AddJsonApi<MyDbContext>(ConfigureJsonApiOptions, discovery => discovery.AddCurrentAssembly());
Update 2021-05-12. The same issue applies to resource services (derived from JsonApiResourceService<TResource, TId>
) and resource definitions (derived from JsonApiResourceDefinition<TResource, TId>
) that are not co-located with the resources (e.g., Document
) referenced by the type argument TResource
. The expected and actual behavior descriptions reflect this new insight.
EXPECTED BEHAVIOR
Resource definitions, services, repositories, and hooks (called "injectables" in the ServiceDiscoveryFacade
) should be discoverable even if they are not co-located with the resources.
ACTUAL BEHAVIOR
"Injectables" are not automatically discovered if they are not co-located with the resources, in which case they must be registered manually.
VERSIONS USED
- JsonApiDotNetCore version:
4.1.1
- ASP.NET Core version:
5.0
- Entity Framework Core version:
5.0
- Database provider:
SQL Server