@@ -721,105 +721,4 @@ However commands executed via Background Jobs have additional context your comma
721
721
access during execution, including the ` BackgroundJob ` itself, the ` CancellationToken ` and
722
722
an Authenticated User Context.
723
723
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