Skip to content

Commit

Permalink
Merge pull request #56 from NoxOrg/feature/extending-nox
Browse files Browse the repository at this point in the history
Changed OnExecuting and OnCompleted method refs to async
  • Loading branch information
Mornevanzyl authored Nov 6, 2023
2 parents c740442 + d1e4621 commit c1390c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/pages/en/nox-lib-custom-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ layout: ../../layouts/MainLayout.astro
***
Nox offers several ways to customise commands. They are:

- Extend the generated command handler by overriding the `OnExecuting` and/or `OnCompleted` methods.
- Extend the generated command handler by overriding the `OnExecutingAsync` and/or `OnCompletedAsync` methods.
- Access non-entity properties that we created on our custom DTOs.
- Override the `Handle` method of the generated handler to completely implement your own command handler.

## Change Request or Entity

During execution of the command we can modify the request by overriding the `OnExecuting` method of the base command handler. We can also modify the content of the command entity by overriding the `OnCompleted` method. Note also that we have access to the additional properties that we added to our custom DTO earlier.
During execution of the command we can modify the request by overriding the `OnExecutingAsync` method of the base command handler. We can also modify the content of the command entity by overriding the `OnCompletedAsync` method. Note also that we have access to the additional properties that we added to our custom DTO earlier.

See the code snippet below for an example:

Expand All @@ -24,17 +24,17 @@ using Microsoft.IdentityModel.Tokens;

namespace Cryptocash.Application.Commands;

public partial class CreateCurrencyCommandHandler
internal partial class CreateCurrencyCommandHandler
{
protected override void OnExecuting(CreateCurrencyCommand request)
protected override async Task OnExecutingAsync(CreateCurrencyCommand request)
{
if (request.EntityDto.ISO_Alpha3.IsNullOrEmpty())
{
request.EntityDto.IsTradeable = false;
}
}

protected override void OnCompleted(CreateCurrencyCommand request, Currency entity)
protected override async Task OnCompletedAsync(CreateCurrencyCommand request, Currency entity)
{
entity.Name = Nox.Types.Text.From(entity.Name.Value.Titleize());

Expand All @@ -58,8 +58,8 @@ using Cryptocash.Application.Dto;

namespace Cryptocash.Application.Commands;

public partial class CreateCurrencyCommandHandler
{
internal partial class CreateCurrencyCommandHandler
{
public override async Task<CurrencyKeyDto> Handle(CreateCurrencyCommand request, CancellationToken cancellationToken)
{
// Custom code to implement the handler
Expand Down
4 changes: 2 additions & 2 deletions src/pages/en/nox-lib-custom-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using Cryptocash.Application.Dto;

namespace Cryptocash.Application.Queries;

public partial class GetCurrencyByIdQueryHandler
internal partial class GetCurrencyByIdQueryHandler
{
public override Task<IQueryable<CurrencyDto>> Handle(GetCurrencyByIdQuery request, CancellationToken cancellationToken)
{
Expand All @@ -45,7 +45,7 @@ using Microsoft.IdentityModel.Tokens;

namespace Cryptocash.Application.Queries;

public partial class GetCurrenciesQueryHandler
internal partial class GetCurrenciesQueryHandler
{
protected override IQueryable<CurrencyDto> OnResponse(IQueryable<CurrencyDto> response)
{
Expand Down

0 comments on commit c1390c1

Please sign in to comment.