Skip to content

Commit 55408c9

Browse files
authored
Merge pull request #1515 from json-api-dotnet/clarify-controller-docs
Docs: Clarify that it's fine to use explicit controllers
2 parents f3c8ebd + f568654 commit 55408c9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

docs/usage/extensibility/controllers.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

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

5+
## Auto-generated controllers
6+
57
_since v5_
68

79
Controllers are auto-generated (using [source generators](https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview)) when you add `[Resource]` on your model class:
@@ -14,7 +16,12 @@ public class Article : Identifiable<Guid>
1416
}
1517
```
1618

17-
## Resource Access Control
19+
> [!NOTE]
20+
> Auto-generated controllers are convenient to get started, but may not work as expected with certain customizations.
21+
> 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.
22+
> In such cases, it's perfectly fine to use [explicit controllers](#explicit-controllers) instead.
23+
24+
### Resource Access Control
1825

1926
It is often desirable to limit which endpoints are exposed on your controller.
2027
A subset can be specified too:
@@ -52,7 +59,7 @@ DELETE http://localhost:14140/articles/1 HTTP/1.1
5259
}
5360
```
5461

55-
## Augmenting controllers
62+
### Augmenting controllers
5663

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

@@ -91,9 +98,9 @@ partial class ArticlesController
9198
In case you don't want to use auto-generated controllers and define them yourself (see below), remove
9299
`[Resource]` from your models or use `[Resource(GenerateControllerEndpoints = JsonApiEndpoints.None)]`.
93100

94-
## Earlier versions
101+
## Explicit controllers
95102

96-
In earlier versions of JsonApiDotNetCore, you needed to create controllers that inherit from `JsonApiController<TResource, TId>`. For example:
103+
To define your own controller class, inherit from `JsonApiController<TResource, TId>`. For example:
97104

98105
```c#
99106
public class ArticlesController : JsonApiController<Article, Guid>

0 commit comments

Comments
 (0)