Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/usage/common-pitfalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Did you notice the missing type of the `LoginAccount.Customer` property? We must
This is only one of the issues you'll run into. Just don't go there.

The right way to model this is by having only `Customer` instead of `WebCustomer` and `AdminCustomer`. And then:
- Hide the `CreditRating` property for web users using [this](https://www.jsonapi.net/usage/extensibility/resource-definitions.html#excluding-fields) approach.
- Hide the `CreditRating` property for web users using [this](~/usage/extensibility/resource-definitions.md#excluding-fields) approach.
- Block web users from setting the `CreditRating` property from POST/PATCH resource endpoints by either:
- Detecting if the `CreditRating` property has changed, such as done [here](https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/RequestBody/WorkflowDefinition.cs).
- Injecting `ITargetedFields`, throwing an error when it contains the `CreditRating` property.
Expand Down Expand Up @@ -87,6 +87,11 @@ Neither sounds very compelling. If stored procedures is what you need, you're be
Although recommended by Microsoft for hard-written controllers, the opinionated behavior of [`[ApiController]`](https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-7.0#apicontroller-attribute) violates the JSON:API specification.
Despite JsonApiDotNetCore trying its best to deal with it, the experience won't be as good as leaving it out.

#### Don't use auto-generated controllers with shared models

When model classes are defined in a separate project, the controllers are generated in that project as well, which is probably not what you want.
For details, see [here](~/usage/extensibility/controllers.md#auto-generated-controllers).

#### Register/override injectable services
Register your JSON:API resource services, resource definitions and repositories with `services.AddResourceService/AddResourceDefinition/AddResourceRepository()` instead of `services.AddScoped()`.
When using [Auto-discovery](~/usage/resource-graph.md#auto-discovery), you don't need to register these at all.
Expand Down
Loading