Need guidance for resource hooks
See original GitHub issueDescription
I have been trying to get Resource Hooks working in v4.0.0-alpha3. I have followed the steps in the docs, but the hook is never hit.
The only way I have actually gotten it to work is to add an explicit call to AddScoped<IResourceHookContainer<WeatherForecast>, WeatherForecastDefinition>()
, then inject the IResourceHookContainer<WeatherForecast>
directly into the service. But that seems wrong - looking at the source it should be registered automatically using open generics.
I also run into problems trying to call BeforeCreate
because I would then have to magically have a IAffectedResources
object somehow. Which seems only to be available internally through some TypeHelper
extension methods and internal derived classes.
Getting this to work is a blocker for me using this library in production code because I have to be able to authenticate and authorize at the request level.
Anyway, I have posted a simple repository that reproduces the behavior: https://github.com/crgolden/JsonApiDotNetCoreIssue. Please take a look and let me know what I’m doing wrong.
Thanks! …
Environment
- JsonApiDotNetCore Version: 4.0.0-alpha3
- Other Relevant Package Versions: not sure
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
@crgolden I’m waiting for #618 to be approved after which I will immediately release v4.0.0-alpha4 which you can use in your corporate projects. After that no more alpha releases, we’ll be aiming for the full release of v4 (unless new immediate bugs show up). But for that I want to completely integrate it our own corporate projects first to beta (battle) test it, and write a migration guide for people coming from v3.1
@maurei Thanks for the response!
Your solution worked for the simple example I shared. Then I spent several hours banging my head against the wall trying to figure out why I still couldn’t get it to work in an existing application.
Finally, I started recreating the existing application entirely from scratch to pinpoint the issue. It turns out that, as soon as the entities are moved to a separate assembly, the resource hooks no longer work. That is a big gotcha.
I updated my sample repo to reproduce the problem. Comment the
WeatherForecast
in the “Entities” project and uncomment the one in the “JsonApiDotNetCoreIssue” project and the resource hooks start working again.This would be a blocking issue for me, as I can hardly guarantee the entities will always be in the same assembly. They may even be coming from a NuGet package, etc.