From 5f907fb08b7eff696de843ef04417fe9379fce9a Mon Sep 17 00:00:00 2001 From: bkoelman Date: Sat, 23 Mar 2024 10:15:13 +0000 Subject: [PATCH] Auto-generated documentation from 55408c90fd07538e564fc5286c3e03f6e70d12ae --- usage/extensibility/controllers.html | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/usage/extensibility/controllers.html b/usage/extensibility/controllers.html index 74ab1a6585..2e45325016 100644 --- a/usage/extensibility/controllers.html +++ b/usage/extensibility/controllers.html @@ -83,6 +83,7 @@
Table of Contents

Controllers

To expose API endpoints, ASP.NET controllers need to be defined.

+

Auto-generated controllers

since v5

Controllers are auto-generated (using source generators) when you add [Resource] on your model class:

[Resource] // Generates ArticlesController.g.cs
@@ -91,7 +92,13 @@ 

Controllers

// ... }
-

Resource Access Control

+
+
Note
+

Auto-generated controllers are convenient to get started, but may not work as expected with certain customizations. +For example, 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. +In such cases, it's perfectly fine to use explicit controllers instead.

+
+

Resource Access Control

It is often desirable to limit which endpoints are exposed on your controller. A subset can be specified too:

[Resource(GenerateControllerEndpoints =
@@ -119,7 +126,7 @@ 

Resource Access Control

] }
-

Augmenting controllers

+

Augmenting controllers

Auto-generated controllers can easily be augmented because they are partial classes. For example:

[DisableRoutingConvention]
 [Route("some/custom/route")]
@@ -150,8 +157,8 @@ 

Augmenting controllers

In case you don't want to use auto-generated controllers and define them yourself (see below), remove [Resource] from your models or use [Resource(GenerateControllerEndpoints = JsonApiEndpoints.None)].

-

Earlier versions

-

In earlier versions of JsonApiDotNetCore, you needed to create controllers that inherit from JsonApiController<TResource, TId>. For example:

+

Explicit controllers

+

To define your own controller class, inherit from JsonApiController<TResource, TId>. For example:

public class ArticlesController : JsonApiController<Article, Guid>
 {
     public ArticlesController(IJsonApiOptions options, IResourceGraph resourceGraph,