Skip to content

Commit b46d299

Browse files
committed
add documentation
1 parent e792b8e commit b46d299

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

docs/Models.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ public class Person : Identifiable<int>
5656
}
5757
```
5858

59+
### Immutability
60+
61+
Attributes can be marked as immutable which will prevent `PATCH` requests
62+
from updating them:
63+
64+
```csharp
65+
public class Person : Identifiable<int>
66+
{
67+
[Attr("first-name", immutable: true)]
68+
public string FirstName { get; set; }
69+
}
70+
```
71+
5972
## Relationships
6073

6174
In order for navigation properties to be identified in the model,

docs/ResourceServices.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)