Skip to content

docs: update simple sample for repositoryAccessor #898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/usage/extensibility/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public class ArticlesController : BaseJsonApiController<Article>
{ }

[HttpGet]
public override async Task<IActionResult> GetAsync()
public override async Task<IActionResult> GetAsync(CancellationToken cancellationToken)
{
return await base.GetAsync();
return await base.GetAsync(cancellationToken);
}

[HttpGet("{id}")]
public override async Task<IActionResult> GetAsync(int id)
public override async Task<IActionResult> GetAsync(int id, CancellationToken cancellationToken)
{
return await base.GetAsync(id);
return await base.GetAsync(id, cancellationToken);
}
}
```
Expand Down Expand Up @@ -108,9 +108,9 @@ public class ReportsController : BaseJsonApiController<Report>
{ }

[HttpGet]
public override async Task<IActionResult> GetAsync()
public override async Task<IActionResult> GetAsync(CancellationToken cancellationToken)
{
return await base.GetAsync();
return await base.GetAsync(cancellationToken);
}
}
```
5 changes: 3 additions & 2 deletions docs/usage/extensibility/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ public class ArticleRepository : EntityFrameworkCoreRepository<Article>
_authenticationService = authenticationService;
}

public override IQueryable<Article> GetAll()
public override IQueryable<Article> GetAll(CancellationToken cancellationToken)
{
return base.Get().Where(article => article.UserId == _authenticationService.UserId);
return base.GetAll(cancellationToken)
.Where(article => article.UserId == _authenticationService.UserId);
}
}
```
Expand Down
24 changes: 12 additions & 12 deletions docs/usage/extensibility/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ public class TodoItemService : JsonApiResourceService<TodoItem>
private readonly INotificationService _notificationService;

public TodoItemService(
IResourceRepository<TodoItem> repository,
IResourceRepositoryAccessor repositoryAccessor,
IQueryLayerComposer queryLayerComposer,
IPaginationContext paginationContext,
IJsonApiOptions options,
ILoggerFactory loggerFactory,
IJsonApiRequest request,
IResourceChangeTracker<TodoItem> resourceChangeTracker,
IResourceFactory resourceFactory,
IResourceHookExecutor hookExecutor = null)
: base(repository, queryLayerComposer, paginationContext, options, loggerFactory,
IResourceHookExecutorFacade hookExecutor)
: base(repositoryAccessor, queryLayerComposer, paginationContext, options, loggerFactory,
request, resourceChangeTracker, resourceFactory, hookExecutor)
{
_notificationService = notificationService;
}

public override async Task<TodoItem> CreateAsync(TodoItem resource)
public override async Task<TodoItem> CreateAsync(TodoItem resource, CancellationToken cancellationToken)
{
// Call the base implementation
var newResource = await base.CreateAsync(resource);
var newResource = await base.CreateAsync(resource, cancellationToken);

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

return newResource;
}
Expand Down Expand Up @@ -70,9 +70,9 @@ public class ProductService : IResourceService<Product>
_dao = dao;
}

public Task<IEnumerable<Product>> GetAsync()
public async Task<IReadOnlyCollection<Product>> GetAsync(CancellationToken cancellationToken)
{
return await _dao.GetProductsAsync();
return await _dao.GetProductsAsync(cancellationToken);
}
}
```
Expand Down Expand Up @@ -162,15 +162,15 @@ public class ArticlesController : BaseJsonApiController<Article>
{ }

[HttpPost]
public override async Task<IActionResult> PostAsync([FromBody] Article resource)
public override async Task<IActionResult> PostAsync([FromBody] Article resource, CancellationToken cancellationToken)
{
return await base.PostAsync(resource);
return await base.PostAsync(resource, cancellationToken);
}

[HttpDelete("{id}")]
public override async Task<IActionResult>DeleteAsync(int id)
public override async Task<IActionResult>DeleteAsync(int id, CancellationToken cancellationToken)
{
return await base.DeleteAsync(id);
return await base.DeleteAsync(id, cancellationToken);
}
}
```