Skip to content

Commit f2da150

Browse files
committed
integrate v8.4 docs into commands
1 parent ebc7b9a commit f2da150

File tree

5 files changed

+346
-140
lines changed

5 files changed

+346
-140
lines changed

MyApp/_includes/command-types.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
To reduce the effort in creating commands with a `IRequest` context we've added a number ergonomic
2+
base classes to better capture the different call-styles a unit of logic can have including
3+
**Sync** or **Async** execution, whether they require **Input Arguments** or have **Result Outputs**.
4+
5+
Choosing the appropriate Abstract base class benefits from IDE tooling in generating the method
6+
signature that needs to be implemented whilst Async commands with Cancellation Tokens in its method
7+
signature highlights any missing async methods that are called without the token.
8+
9+
### Sync Commands
10+
11+
- `SyncCommand` - Requires No Arguments
12+
- `SyncCommand<TRequest>` - Requires TRequest Argument
13+
- `SyncCommandWithResult<TResult>` - Requires No Args and returns Result
14+
- `SyncCommandWithResult<TRequest,TResult>` - Requires Argument and returns Result
15+
16+
```csharp
17+
public record MyArgs(int Id);
18+
public record MyResult(string Message);
19+
20+
public class MyCommandNoArgs(ILogger<MyCommandNoArgs> log) : SyncCommand
21+
{
22+
protected override void Run()
23+
{
24+
log.LogInformation("Called with No Args");
25+
}
26+
}
27+
28+
public class MyCommandArgs(ILogger<MyCommandNoArgs> log) : SyncCommand<MyArgs>
29+
{
30+
protected override void Run(MyArgs request)
31+
{
32+
log.LogInformation("Called with {Id}", request.Id);
33+
}
34+
}
35+
36+
public class MyCommandWithResult(ILogger<MyCommandNoArgs> log) : SyncCommandWithResult<MyResult>
37+
{
38+
protected override MyResult Run()
39+
{
40+
log.LogInformation("Called with No Args and returns Result");
41+
return new MyResult("Hello World");
42+
}
43+
}
44+
45+
public class MyCommandWithArgsAndResult(ILogger<MyCommandNoArgs> log)
46+
: SyncCommandWithResult<MyArgs,MyResult>
47+
{
48+
protected override MyResult Run(MyArgs request)
49+
{
50+
log.LogInformation("Called with {Id} and returns Result", request.Id);
51+
return new MyResult("Hello World");
52+
}
53+
}
54+
```
55+
56+
### Async Commands
57+
58+
- `AsyncCommand` - Requires No Arguments
59+
- `AsyncCommand<TRequest>` - Requires TRequest Argument
60+
- `AsyncCommandWithResult<TResult>` - Requires No Args and returns Result
61+
- `AsyncCommandWithResult<TReq,TResult>` - Requires Argument and returns Result
62+
63+
```csharp
64+
public class MyAsyncCommandNoArgs(ILogger<MyCommandNoArgs> log) : AsyncCommand
65+
{
66+
protected override async Task RunAsync(CancellationToken token)
67+
{
68+
log.LogInformation("Async called with No Args");
69+
}
70+
}
71+
72+
public class MyAsyncCommandArgs(ILogger<MyCommandNoArgs> log)
73+
: AsyncCommand<MyArgs>
74+
{
75+
protected override async Task RunAsync(MyArgs request, CancellationToken token)
76+
{
77+
log.LogInformation("Async called with {Id}", request.Id);
78+
}
79+
}
80+
81+
public class MyAsyncCommandWithResult(ILogger<MyCommandNoArgs> log)
82+
: AsyncCommandWithResult<MyResult>
83+
{
84+
protected override async Task<MyResult> RunAsync(CancellationToken token)
85+
{
86+
log.LogInformation("Async called with No Args and returns Result");
87+
return new MyResult("Hello World");
88+
}
89+
}
90+
91+
public class MyAsyncCommandWithArgsAndResult(ILogger<MyCommandNoArgs> log)
92+
: AsyncCommandWithResult<MyArgs,MyResult>
93+
{
94+
protected override async Task<MyResult> RunAsync(
95+
MyArgs request, CancellationToken token)
96+
{
97+
log.LogInformation("Called with {Id} and returns Result", request.Id);
98+
return new MyResult("Hello World");
99+
}
100+
}
101+
```

MyApp/_pages/background-jobs.md

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -721,105 +721,4 @@ However commands executed via Background Jobs have additional context your comma
721721
access during execution, including the `BackgroundJob` itself, the `CancellationToken` and
722722
an Authenticated User Context.
723723

724-
To reduce the effort in creating commands with a `IRequest` context we've added a number ergonomic
725-
base classes to better capture the different call-styles a unit of logic can have including
726-
**Sync** or **Async** execution, whether they require **Input Arguments** or have **Result Outputs**.
727-
728-
Choosing the appropriate Abstract base class benefits from IDE tooling in generating the method
729-
signature that needs to be implemented whilst Async commands with Cancellation Tokens in its method
730-
signature highlights any missing async methods that are called without the token.
731-
732-
### Sync Commands
733-
734-
- `SyncCommand` - Requires No Arguments
735-
- `SyncCommand<TRequest>` - Requires TRequest Argument
736-
- `SyncCommandWithResult<TResult>` - Requires No Args and returns Result
737-
- `SyncCommandWithResult<TReq,TResult>` - Requires Arg and returns Result
738-
739-
```csharp
740-
public record MyArgs(int Id);
741-
public record MyResult(string Message);
742-
743-
public class MyCommandNoArgs(ILogger<MyCommandNoArgs> log) : SyncCommand
744-
{
745-
protected override void Run()
746-
{
747-
log.LogInformation("Called with No Args");
748-
}
749-
}
750-
751-
public class MyCommandArgs(ILogger<MyCommandNoArgs> log) : SyncCommand<MyArgs>
752-
{
753-
protected override void Run(MyArgs request)
754-
{
755-
log.LogInformation("Called with {Id}", request.Id);
756-
}
757-
}
758-
759-
public class MyCommandWithResult(ILogger<MyCommandNoArgs> log)
760-
: SyncCommandWithResult<MyResult>
761-
{
762-
protected override MyResult Run()
763-
{
764-
log.LogInformation("Called with No Args and returns Result");
765-
return new MyResult("Hello World");
766-
}
767-
}
768-
769-
public class MyCommandWithArgsAndResult(ILogger<MyCommandNoArgs> log)
770-
: SyncCommandWithResult<MyArgs,MyResult>
771-
{
772-
protected override MyResult Run(MyArgs request)
773-
{
774-
log.LogInformation("Called with {Id} and returns Result", request.Id);
775-
return new MyResult("Hello World");
776-
}
777-
}
778-
```
779-
780-
### Async Commands
781-
782-
- `AsyncCommand` - Requires No Arguments
783-
- `AsyncCommand<TRequest>` - Requires TRequest Argument
784-
- `AsyncCommandWithResult<TResult>` - Requires No Args and returns Result
785-
- `AsyncCommandWithResult<TReq,TResult>` - Requires Arg and returns Result
786-
787-
```csharp
788-
public class MyAsyncCommandNoArgs(ILogger<MyCommandNoArgs> log) : AsyncCommand
789-
{
790-
protected override async Task RunAsync(CancellationToken token)
791-
{
792-
log.LogInformation("Async called with No Args");
793-
}
794-
}
795-
796-
public class MyAsyncCommandArgs(ILogger<MyCommandNoArgs> log)
797-
: AsyncCommand<MyArgs>
798-
{
799-
protected override async Task RunAsync(MyArgs request, CancellationToken t)
800-
{
801-
log.LogInformation("Async called with {Id}", request.Id);
802-
}
803-
}
804-
805-
public class MyAsyncCommandWithResult(ILogger<MyCommandNoArgs> log)
806-
: AsyncCommandWithResult<MyResult>
807-
{
808-
protected override async Task<MyResult> RunAsync(CancellationToken token)
809-
{
810-
log.LogInformation("Async called with No Args and returns Result");
811-
return new MyResult("Hello World");
812-
}
813-
}
814-
815-
public class MyAsyncCommandWithArgsAndResult(ILogger<MyCommandNoArgs> log)
816-
: AsyncCommandWithResult<MyArgs,MyResult>
817-
{
818-
protected override async Task<MyResult> RunAsync(
819-
MyArgs request, CancellationToken token)
820-
{
821-
log.LogInformation("Called with {Id} and returns Result", request.Id);
822-
return new MyResult("Hello World");
823-
}
824-
}
825-
```
724+
::include command-types.md::

0 commit comments

Comments
 (0)