@@ -75,4 +75,62 @@ public class MyModelService : IResourceService<MyModel>
7575 return await _dal .GetModelAsync ();
7676 }
7777}
78+ ```
79+
80+ ### Limited Requirements
81+
82+ In some cases it may be necessary to only expose a few methods on the resource.
83+ For this reason, we have created a hierarchy of service interfaces that can be used to get the
84+ exact implementation you require. Below is a table outlining these interfaces:
85+
86+ | METHOD | IResourceService | IResourceCmdService | IResourceQueryService | IGetAllService | IGetByIdService | IGetRelationshipService | IGetRelationships | ICreateService | IDeleteService | IUpdateService | IUpdateRelationshipService |
87+ | ------------------------------------------| :----------------:| :-------------------:| :---------------------:| :--------------:| :---------------:| :-----------------------:| :-----------------:| :--------------:| :--------------:| :--------------:| :--------------------------:|
88+ | GET / | ✓ | | ✓ | ✓ | | | | | | | |
89+ | GET /{id} | ✓ | | ✓ | | ✓ | | | | | | |
90+ | GET /{id}/{relationship} | ✓ | | ✓ | | | ✓ | | | | | |
91+ | GET /{id}/relationships/{relationship} | ✓ | | ✓ | | | | ✓ | | | | |
92+ | POST / | ✓ | ✓ | | | | | | ✓ | | | |
93+ | DELETE /{id} | ✓ | ✓ | | | | | | | ✓ | | |
94+ | PATCH /{id} | ✓ | ✓ | | | | | | | | ✓ | |
95+ | PATCH /{id}/relationships/{relationship} | ✓ | ✓ | | | | | | | | | ✓ |
96+
97+ In order to take advantage of these interfaces you first need to inject the service for each implemented interface.
98+ Using Autofac, as an example, this is simply:
99+
100+ ``` csharp
101+ public class MyResourceService : ICreateService <MyResource >, IDeleteService <MyResource > {
102+ // ...
103+ }
104+
105+ public class Startup {
106+ public IServiceProvider ConfigureServices (IServiceCollection services ) {
107+ // ...
108+ builder .RegisterType <MyResourceService >().AsImplementedInterfaces ();
109+ // ...
110+ }
111+ }
112+ ```
113+
114+ Then in the controller, you should inherit the base controller and pass the services into
115+ the named, optional base parameters:
116+
117+ ``` csharp
118+ public class MyResourcesController : BaseJsonApiController <MyResource , int > {
119+ public MyResourcesController (
120+ IJsonApiContext jsonApiContext ,
121+ ICreateService <MyResource > create ,
122+ IDeleteService <MyResource > delete )
123+ : base (
124+ jsonApiContext ,
125+ create : create , // <--- pass the services to the base controller using named optional parameters
126+ delete : delete ) { }
127+
128+ [HttpPost ]
129+ public override async Task <IActionResult > PostAsync ([FromBody ] MyResource entity )
130+ => await base .PostAsync (entity );
131+
132+ [HttpDelete (" {id}" )]
133+ public override async Task<IActionResult>DeleteAsync (int id )
134+ => await base .DeleteAsync (id );
135+ }
78136```
0 commit comments