Skip to content

Commit ccaff6d

Browse files
fdlaneBart Koelman
and
Bart Koelman
authoredNov 30, 2020
docs: update simple sample for repositoryAccessor (#898)
* docs: update simple sample for repositoryAccessor * Updated additional places in docs for CancellationToken usage Co-authored-by: Bart Koelman <[email protected]>
1 parent 5467c79 commit ccaff6d

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed
 

‎docs/usage/extensibility/controllers.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ public class ArticlesController : BaseJsonApiController<Article>
5151
{ }
5252

5353
[HttpGet]
54-
public override async Task<IActionResult> GetAsync()
54+
public override async Task<IActionResult> GetAsync(CancellationToken cancellationToken)
5555
{
56-
return await base.GetAsync();
56+
return await base.GetAsync(cancellationToken);
5757
}
5858

5959
[HttpGet("{id}")]
60-
public override async Task<IActionResult> GetAsync(int id)
60+
public override async Task<IActionResult> GetAsync(int id, CancellationToken cancellationToken)
6161
{
62-
return await base.GetAsync(id);
62+
return await base.GetAsync(id, cancellationToken);
6363
}
6464
}
6565
```
@@ -108,9 +108,9 @@ public class ReportsController : BaseJsonApiController<Report>
108108
{ }
109109

110110
[HttpGet]
111-
public override async Task<IActionResult> GetAsync()
111+
public override async Task<IActionResult> GetAsync(CancellationToken cancellationToken)
112112
{
113-
return await base.GetAsync();
113+
return await base.GetAsync(cancellationToken);
114114
}
115115
}
116116
```

‎docs/usage/extensibility/repositories.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ public class ArticleRepository : EntityFrameworkCoreRepository<Article>
5151
_authenticationService = authenticationService;
5252
}
5353

54-
public override IQueryable<Article> GetAll()
54+
public override IQueryable<Article> GetAll(CancellationToken cancellationToken)
5555
{
56-
return base.Get().Where(article => article.UserId == _authenticationService.UserId);
56+
return base.GetAll(cancellationToken)
57+
.Where(article => article.UserId == _authenticationService.UserId);
5758
}
5859
}
5960
```

‎docs/usage/extensibility/services.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ public class TodoItemService : JsonApiResourceService<TodoItem>
1616
private readonly INotificationService _notificationService;
1717

1818
public TodoItemService(
19-
IResourceRepository<TodoItem> repository,
19+
IResourceRepositoryAccessor repositoryAccessor,
2020
IQueryLayerComposer queryLayerComposer,
2121
IPaginationContext paginationContext,
2222
IJsonApiOptions options,
2323
ILoggerFactory loggerFactory,
2424
IJsonApiRequest request,
2525
IResourceChangeTracker<TodoItem> resourceChangeTracker,
2626
IResourceFactory resourceFactory,
27-
IResourceHookExecutor hookExecutor = null)
28-
: base(repository, queryLayerComposer, paginationContext, options, loggerFactory,
27+
IResourceHookExecutorFacade hookExecutor)
28+
: base(repositoryAccessor, queryLayerComposer, paginationContext, options, loggerFactory,
2929
request, resourceChangeTracker, resourceFactory, hookExecutor)
3030
{
3131
_notificationService = notificationService;
3232
}
3333

34-
public override async Task<TodoItem> CreateAsync(TodoItem resource)
34+
public override async Task<TodoItem> CreateAsync(TodoItem resource, CancellationToken cancellationToken)
3535
{
3636
// Call the base implementation
37-
var newResource = await base.CreateAsync(resource);
37+
var newResource = await base.CreateAsync(resource, cancellationToken);
3838

3939
// Custom code
40-
_notificationService.Notify($"Resource created: {newResource.StringId}");
40+
await _notificationService.NotifyAsync($"Resource created: {newResource.StringId}");
4141

4242
return newResource;
4343
}
@@ -70,9 +70,9 @@ public class ProductService : IResourceService<Product>
7070
_dao = dao;
7171
}
7272

73-
public Task<IEnumerable<Product>> GetAsync()
73+
public async Task<IReadOnlyCollection<Product>> GetAsync(CancellationToken cancellationToken)
7474
{
75-
return await _dao.GetProductsAsync();
75+
return await _dao.GetProductsAsync(cancellationToken);
7676
}
7777
}
7878
```
@@ -162,15 +162,15 @@ public class ArticlesController : BaseJsonApiController<Article>
162162
{ }
163163

164164
[HttpPost]
165-
public override async Task<IActionResult> PostAsync([FromBody] Article resource)
165+
public override async Task<IActionResult> PostAsync([FromBody] Article resource, CancellationToken cancellationToken)
166166
{
167-
return await base.PostAsync(resource);
167+
return await base.PostAsync(resource, cancellationToken);
168168
}
169169

170170
[HttpDelete("{id}")]
171-
public override async Task<IActionResult>DeleteAsync(int id)
171+
public override async Task<IActionResult>DeleteAsync(int id, CancellationToken cancellationToken)
172172
{
173-
return await base.DeleteAsync(id);
173+
return await base.DeleteAsync(id, cancellationToken);
174174
}
175175
}
176176
```

0 commit comments

Comments
 (0)
Please sign in to comment.