Class ControllerBaseExtensions
- Namespace
- Whipstaff.AspNetCore.Extensions
- Assembly
- Whipstaff.AspNetCore.dll
Extension methods for ASP.NET Core Controllers.
public static class ControllerBaseExtensions
- Inheritance
-
ControllerBaseExtensions
- Inherited Members
Methods
GetAddActionAsync<TAddRequestDto, TAddResponseDto, TAddCommand>(ControllerBase, ILogger, IMediator, IAuthorizationService, TAddRequestDto, Action<ILogger, string, Exception?>, string, Func<TAddResponseDto, Task<ActionResult<TAddResponseDto>>>, Func<TAddRequestDto, ClaimsPrincipal, CancellationToken, Task<TAddCommand>>, CancellationToken)
Extension method for common behaviour in Add API operations.
public static Task<ActionResult<TAddResponseDto>> GetAddActionAsync<TAddRequestDto, TAddResponseDto, TAddCommand>(this ControllerBase instance, ILogger logger, IMediator mediator, IAuthorizationService authorizationService, TAddRequestDto addRequestDto, Action<ILogger, string, Exception?> logAction, string addPolicyName, Func<TAddResponseDto, Task<ActionResult<TAddResponseDto>>> getAddActionResultAsync, Func<TAddRequestDto, ClaimsPrincipal, CancellationToken, Task<TAddCommand>> addCommandFactoryAsync, CancellationToken cancellationToken) where TAddCommand : IAuditableRequest<TAddRequestDto, TAddResponseDto?>
Parameters
instance
ControllerBaseWeb Controller instance.
logger
ILoggerLogger object.
mediator
IMediatorMediatr object for publishing commands to.
authorizationService
IAuthorizationServiceAuthorization service.
addRequestDto
TAddRequestDtoThe Request DTO for the Add operation.
logAction
Action<ILogger, string, Exception>Log Message Action for the event to log against.
You can create and cache a LoggerMessage action to pass in by calling Define<T1>(LogLevel, EventId, string). You can either have a single LoggerMessage definition for all controllers, or have one for each controller. The flexibility is there for you to choose.
addPolicyName
stringThe policy name to use for Authorization verification.
getAddActionResultAsync
Func<TAddResponseDto, Task<ActionResult<TAddResponseDto>>>Task to format the result of CQRS operation into an IActionResult. Allows for controllers to make decisions on what views or data manipulation to carry out.
addCommandFactoryAsync
Func<TAddRequestDto, ClaimsPrincipal, CancellationToken, Task<TAddCommand>>The Command Factory for the Add operation.
cancellationToken
CancellationTokenThe cancellation token for the operation.
Returns
- Task<ActionResult<TAddResponseDto>>
A Task<TResult> representing the result of the asynchronous operation.
Type Parameters
TAddRequestDto
The type for the Request DTO for the Add Operation.
TAddResponseDto
The type for the Response DTO for the Add Operation.
TAddCommand
The type for the CQRS Command for the Add Operation.
GetApiListActionAsync<TListRequestDto, TListResponseDto, TListQuery>(ControllerBase, ILogger, IMediator, IAuthorizationService, TListRequestDto, Action<ILogger, string, Exception?>, string, Func<TListResponseDto, Task<ActionResult<TListResponseDto>>>, Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>>, CancellationToken)
Extension method for common behaviour in List API operations.
public static Task<ActionResult<TListResponseDto>> GetApiListActionAsync<TListRequestDto, TListResponseDto, TListQuery>(this ControllerBase instance, ILogger logger, IMediator mediator, IAuthorizationService authorizationService, TListRequestDto listRequestDto, Action<ILogger, string, Exception?> logAction, string listPolicyName, Func<TListResponseDto, Task<ActionResult<TListResponseDto>>> getListActionResultAsync, Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>> listCommandFactoryAsync, CancellationToken cancellationToken) where TListResponseDto : class where TListQuery : IAuditableRequest<TListRequestDto, TListResponseDto?>
Parameters
instance
ControllerBaseWeb Controller instance.
logger
ILoggerLogger object.
mediator
IMediatorMediatr object for publishing commands to.
authorizationService
IAuthorizationServiceAuthorization service.
listRequestDto
TListRequestDtoThe Request DTO for the List operation.
logAction
Action<ILogger, string, Exception>Log Message Action for the event to log against.
You can create and cache a LoggerMessage action to pass in by calling Define(LogLevel, EventId, string). You can either have a single LoggerMessage definition for all controllers, or have one for each controller. The flexibility is there for you to choose.
listPolicyName
stringThe policy name to use for Authorization verification.
getListActionResultAsync
Func<TListResponseDto, Task<ActionResult<TListResponseDto>>>Task to format the result of CQRS operation into an IActionResult. Allows for controllers to make decisions on what views or data manipulation to carry out.
listCommandFactoryAsync
Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>>The Command Factory for the List operation.
cancellationToken
CancellationTokenThe cancellation token for the operation.
Returns
- Task<ActionResult<TListResponseDto>>
A Task<TResult> representing the result of the asynchronous operation.
Type Parameters
TListRequestDto
The type for the Request DTO for the List Operation.
TListResponseDto
The type for the Response DTO for the List Operation.
TListQuery
The type for the CQRS Command for the List Operation.
GetApiListActionFlexibleAsync<TListRequestDto, TListResponseDto, TListQuery>(ControllerBase, ILogger, IMediator, IAuthorizationService, TListRequestDto, Action<ILogger, string, Exception?>, string, Func<TListResponseDto, Task<ActionResult<TListResponseDto>>>, Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>>, CancellationToken)
Extension method for common behaviour in List API operations, this method doesn't constrain the requirement for an auditable request. However the auditable request does call this.
public static Task<ActionResult<TListResponseDto>> GetApiListActionFlexibleAsync<TListRequestDto, TListResponseDto, TListQuery>(this ControllerBase instance, ILogger logger, IMediator mediator, IAuthorizationService authorizationService, TListRequestDto listRequestDto, Action<ILogger, string, Exception?> logAction, string listPolicyName, Func<TListResponseDto, Task<ActionResult<TListResponseDto>>> getListActionResultAsync, Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>> listCommandFactoryAsync, CancellationToken cancellationToken) where TListResponseDto : class where TListQuery : IRequest<TListResponseDto?>
Parameters
instance
ControllerBaseWeb Controller instance.
logger
ILoggerLogger object.
mediator
IMediatorMediatr object for publishing commands to.
authorizationService
IAuthorizationServiceAuthorization service.
listRequestDto
TListRequestDtoThe Request DTO for the List operation.
logAction
Action<ILogger, string, Exception>Log Message Action for the event to log against.
You can create and cache a LoggerMessage action to pass in by calling Define(LogLevel, EventId, string). You can either have a single LoggerMessage definition for all controllers, or have one for each controller. The flexibility is there for you to choose.
listPolicyName
stringThe policy name to use for Authorization verification.
getListActionResultAsync
Func<TListResponseDto, Task<ActionResult<TListResponseDto>>>Task to format the result of CQRS operation into an IActionResult. Allows for controllers to make decisions on what views or data manipulation to carry out.
listCommandFactoryAsync
Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>>The Command Factory for the List operation.
cancellationToken
CancellationTokenThe cancellation token for the operation.
Returns
- Task<ActionResult<TListResponseDto>>
A Task<TResult> representing the result of the asynchronous operation.
Type Parameters
TListRequestDto
The type for the Request DTO for the List Operation.
TListResponseDto
The type for the Response DTO for the List Operation.
TListQuery
The type for the CQRS Command for the List Operation.
GetApiViewActionAsync<TViewRequestDto, TViewResponseDto, TViewQuery>(ControllerBase, ILogger, IMediator, IAuthorizationService, TViewRequestDto, Action<ILogger, string, Exception?>, string, Func<TViewResponseDto, Task<ActionResult<TViewResponseDto>>>, Func<TViewRequestDto, ClaimsPrincipal, CancellationToken, Task<TViewQuery>>, CancellationToken)
Extension method for common behaviour in View API operations.
public static Task<ActionResult<TViewResponseDto>> GetApiViewActionAsync<TViewRequestDto, TViewResponseDto, TViewQuery>(this ControllerBase instance, ILogger logger, IMediator mediator, IAuthorizationService authorizationService, TViewRequestDto viewRequestDto, Action<ILogger, string, Exception?> logAction, string viewPolicyName, Func<TViewResponseDto, Task<ActionResult<TViewResponseDto>>> getViewActionResultAsync, Func<TViewRequestDto, ClaimsPrincipal, CancellationToken, Task<TViewQuery>> viewCommandFactoryAsync, CancellationToken cancellationToken) where TViewResponseDto : class where TViewQuery : IAuditableRequest<TViewRequestDto, TViewResponseDto?>
Parameters
instance
ControllerBaseWeb Controller instance.
logger
ILoggerLogger object.
mediator
IMediatorMediatr object for publishing commands to.
authorizationService
IAuthorizationServiceAuthorization service.
viewRequestDto
TViewRequestDtoThe Request DTO for the View operation.
logAction
Action<ILogger, string, Exception>Log Message Action for the event to log against.
You can create and cache a LoggerMessage action to pass in by calling Define(LogLevel, EventId, string). You can either have a single LoggerMessage definition for all controllers, or have one for each controller. The flexibility is there for you to choose.
viewPolicyName
stringThe policy name to use for Authorization verification.
getViewActionResultAsync
Func<TViewResponseDto, Task<ActionResult<TViewResponseDto>>>Task to format the result of CQRS operation into an IActionResult. Allows for controllers to make decisions on what views or data manipulation to carry out.
viewCommandFactoryAsync
Func<TViewRequestDto, ClaimsPrincipal, CancellationToken, Task<TViewQuery>>The Command Factory for the View operation.
cancellationToken
CancellationTokenThe cancellation token for the operation.
Returns
- Task<ActionResult<TViewResponseDto>>
A Task<TResult> representing the result of the asynchronous operation.
Type Parameters
TViewRequestDto
The type for the Request DTO for the View Operation.
TViewResponseDto
The type for the Response DTO for the View Operation.
TViewQuery
The type for the CQRS Command for the View Operation.
GetDeleteActionAsync<TDeleteResponseDto, TDeleteCommand>(ControllerBase, ILogger, IMediator, IAuthorizationService, long, Action<ILogger, string, Exception?>, string, Func<TDeleteResponseDto, Task<ActionResult<TDeleteResponseDto>>>, Func<long, ClaimsPrincipal, CancellationToken, Task<TDeleteCommand>>, CancellationToken)
Extension method for common behaviour in Delete API operations.
public static Task<ActionResult<TDeleteResponseDto>> GetDeleteActionAsync<TDeleteResponseDto, TDeleteCommand>(this ControllerBase instance, ILogger logger, IMediator mediator, IAuthorizationService authorizationService, long id, Action<ILogger, string, Exception?> logAction, string deletePolicyName, Func<TDeleteResponseDto, Task<ActionResult<TDeleteResponseDto>>> getDeleteActionResultAsync, Func<long, ClaimsPrincipal, CancellationToken, Task<TDeleteCommand>> deleteCommandFactoryAsync, CancellationToken cancellationToken) where TDeleteCommand : IAuditableRequest<long, TDeleteResponseDto?>
Parameters
instance
ControllerBaseWeb Controller instance.
logger
ILoggerLogger object.
mediator
IMediatorMediatr object for publishing commands to.
authorizationService
IAuthorizationServiceAuthorization service.
id
longUnique Id for the identity being deleted.
logAction
Action<ILogger, string, Exception>Log Message Action for the event to log against.
You can create and cache a LoggerMessage action to pass in by calling Define<T1>(LogLevel, EventId, string). You can either have a single LoggerMessage definition for all controllers, or have one for each controller. The flexibility is there for you to choose.
deletePolicyName
stringThe policy name to use for Authorization verification.
getDeleteActionResultAsync
Func<TDeleteResponseDto, Task<ActionResult<TDeleteResponseDto>>>Task to format the result of CQRS operation into an IActionResult. Allows for controllers to make decisions on what views or data manipulation to carry out.
deleteCommandFactoryAsync
Func<long, ClaimsPrincipal, CancellationToken, Task<TDeleteCommand>>The Command Factory for the Delete operation.
cancellationToken
CancellationTokenThe cancellation token for the operation.
Returns
- Task<ActionResult<TDeleteResponseDto>>
A Task<TResult> representing the result of the asynchronous operation.
Type Parameters
TDeleteResponseDto
The type for the Response DTO for the Add Operation.
TDeleteCommand
The type for the CQRS Command for the Delete Operation.
GetListActionAsync<TListRequestDto, TListResponseDto, TListQuery>(Controller, ILogger, IMediator, IAuthorizationService, TListRequestDto, Action<ILogger, string, Exception?>, string, Func<TListResponseDto, Task<IActionResult>>, Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>>, CancellationToken)
Extension method for common behaviour in List API operations.
public static Task<IActionResult> GetListActionAsync<TListRequestDto, TListResponseDto, TListQuery>(this Controller instance, ILogger logger, IMediator mediator, IAuthorizationService authorizationService, TListRequestDto listRequestDto, Action<ILogger, string, Exception?> logAction, string listPolicyName, Func<TListResponseDto, Task<IActionResult>> getListActionResultAsync, Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>> listCommandFactoryAsync, CancellationToken cancellationToken) where TListResponseDto : class where TListQuery : IAuditableRequest<TListRequestDto, TListResponseDto?>
Parameters
instance
ControllerWeb Controller instance.
logger
ILoggerLogger object.
mediator
IMediatorMediatr object for publishing commands to.
authorizationService
IAuthorizationServiceAuthorization service.
listRequestDto
TListRequestDtoThe Request DTO for the List operation.
logAction
Action<ILogger, string, Exception>Log Message Action for the event to log against.
You can create and cache a LoggerMessage action to pass in by calling Define(LogLevel, EventId, string). You can either have a single LoggerMessage definition for all controllers, or have one for each controller. The flexibility is there for you to choose.
listPolicyName
stringThe policy name to use for Authorization verification.
getListActionResultAsync
Func<TListResponseDto, Task<IActionResult>>Task to format the result of CQRS operation into an IActionResult. Allows for controllers to make decisions on what views or data manipulation to carry out.
listCommandFactoryAsync
Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>>The Command Factory for the List operation.
cancellationToken
CancellationTokenThe cancellation token for the operation.
Returns
- Task<IActionResult>
A Task<TResult> representing the result of the asynchronous operation.
Type Parameters
TListRequestDto
The type for the Request DTO for the List Operation.
TListResponseDto
The type for the Response DTO for the List Operation.
TListQuery
The type for the CQRS Command for the List Operation.
GetListActionFlexibleAsync<TListRequestDto, TListResponseDto, TListQuery>(Controller, ILogger, IMediator, IAuthorizationService, TListRequestDto, Action<ILogger, string, Exception?>, string, Func<TListResponseDto, Task<IActionResult>>, Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>>, CancellationToken)
Extension method for common behaviour in List API operations, this method doesn't constrain the requirement for an auditable request. However the auditable request does call this.
public static Task<IActionResult> GetListActionFlexibleAsync<TListRequestDto, TListResponseDto, TListQuery>(this Controller instance, ILogger logger, IMediator mediator, IAuthorizationService authorizationService, TListRequestDto listRequestDto, Action<ILogger, string, Exception?> logAction, string listPolicyName, Func<TListResponseDto, Task<IActionResult>> getListActionResultAsync, Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>> listCommandFactoryAsync, CancellationToken cancellationToken) where TListResponseDto : class where TListQuery : IRequest<TListResponseDto?>
Parameters
instance
ControllerWeb Controller instance.
logger
ILoggerLogger object.
mediator
IMediatorMediatr object for publishing commands to.
authorizationService
IAuthorizationServiceAuthorization service.
listRequestDto
TListRequestDtoThe Request DTO for the List operation.
logAction
Action<ILogger, string, Exception>Log Message Action for the event to log against.
You can create and cache a LoggerMessage action to pass in by calling Define(LogLevel, EventId, string). You can either have a single LoggerMessage definition for all controllers, or have one for each controller. The flexibility is there for you to choose.
listPolicyName
stringThe policy name to use for Authorization verification.
getListActionResultAsync
Func<TListResponseDto, Task<IActionResult>>Task to format the result of CQRS operation into an IActionResult. Allows for controllers to make decisions on what views or data manipulation to carry out.
listCommandFactoryAsync
Func<TListRequestDto, ClaimsPrincipal, CancellationToken, Task<TListQuery>>The Command Factory for the List operation.
cancellationToken
CancellationTokenThe cancellation token for the operation.
Returns
- Task<IActionResult>
A Task representing the result of the asynchronous operation.
Type Parameters
TListRequestDto
The type for the Request DTO for the List Operation.
TListResponseDto
The type for the Response DTO for the List Operation.
TListQuery
The type for the CQRS Command for the List Operation.
GetUpdateActionAsync<TUpdateRequestDto, TUpdateResponseDto, TUpdateCommand>(ControllerBase, ILogger, IMediator, IAuthorizationService, long, TUpdateRequestDto, Action<ILogger, string, Exception?>, string, Func<TUpdateResponseDto, Task<ActionResult<TUpdateResponseDto>>>, Func<TUpdateRequestDto, ClaimsPrincipal, CancellationToken, Task<TUpdateCommand>>, CancellationToken)
Extension method for common behaviour in Update API operations.
public static Task<ActionResult<TUpdateResponseDto>> GetUpdateActionAsync<TUpdateRequestDto, TUpdateResponseDto, TUpdateCommand>(this ControllerBase instance, ILogger logger, IMediator mediator, IAuthorizationService authorizationService, long id, TUpdateRequestDto updateRequestDto, Action<ILogger, string, Exception?> logAction, string updatePolicyName, Func<TUpdateResponseDto, Task<ActionResult<TUpdateResponseDto>>> getUpdateActionResultAsync, Func<TUpdateRequestDto, ClaimsPrincipal, CancellationToken, Task<TUpdateCommand>> updateCommandFactoryAsync, CancellationToken cancellationToken) where TUpdateResponseDto : class? where TUpdateCommand : IAuditableRequest<TUpdateRequestDto, TUpdateResponseDto?>
Parameters
instance
ControllerBaseWeb Controller instance.
logger
ILoggerLogger object.
mediator
IMediatorMediatr object for publishing commands to.
authorizationService
IAuthorizationServiceAuthorization service.
id
longThe unique id of the entity to be updated.
updateRequestDto
TUpdateRequestDtoThe Request DTO for the Update operation.
logAction
Action<ILogger, string, Exception>Log Message Action for the event to log against.
You can create and cache a LoggerMessage action to pass in by calling Define<T1>(LogLevel, EventId, string). You can either have a single LoggerMessage definition for all controllers, or have one for each controller. The flexibility is there for you to choose.
updatePolicyName
stringThe policy name to use for Authorization verification.
getUpdateActionResultAsync
Func<TUpdateResponseDto, Task<ActionResult<TUpdateResponseDto>>>Task to format the result of CQRS operation into an IActionResult. Allows for controllers to make decisions on what views or data manipulation to carry out.
updateCommandFactoryAsync
Func<TUpdateRequestDto, ClaimsPrincipal, CancellationToken, Task<TUpdateCommand>>The Command Factory for the Update operation.
cancellationToken
CancellationTokenThe cancellation token for the operation.
Returns
- Task<ActionResult<TUpdateResponseDto>>
A Task<TResult> representing the result of the asynchronous operation.
Type Parameters
TUpdateRequestDto
The type for the Request DTO for the Update Operation.
TUpdateResponseDto
The type for the Response DTO for the Update Operation.
TUpdateCommand
The type for the CQRS Command for the Update Operation.
GetViewActionAsync<TViewRequestDto, TViewResponseDto, TViewQuery>(ControllerBase, ILogger, IMediator, IAuthorizationService, TViewRequestDto, Action<ILogger, string, Exception?>, string, Func<TViewResponseDto, Task<IActionResult>>, Func<TViewRequestDto, ClaimsPrincipal, CancellationToken, Task<TViewQuery>>, CancellationToken)
Extension method for common behaviour in View API operations.
public static Task<IActionResult> GetViewActionAsync<TViewRequestDto, TViewResponseDto, TViewQuery>(this ControllerBase instance, ILogger logger, IMediator mediator, IAuthorizationService authorizationService, TViewRequestDto viewRequestDto, Action<ILogger, string, Exception?> logAction, string viewPolicyName, Func<TViewResponseDto, Task<IActionResult>> getViewActionResultAsync, Func<TViewRequestDto, ClaimsPrincipal, CancellationToken, Task<TViewQuery>> viewCommandFactoryAsync, CancellationToken cancellationToken) where TViewResponseDto : class where TViewQuery : IAuditableRequest<TViewRequestDto, TViewResponseDto?>
Parameters
instance
ControllerBaseWeb Controller instance.
logger
ILoggerLogger object.
mediator
IMediatorMediatr object for publishing commands to.
authorizationService
IAuthorizationServiceAuthorization service.
viewRequestDto
TViewRequestDtoThe Request DTO for the View operation.
logAction
Action<ILogger, string, Exception>Log Message Action for the event to log against.
You can create and cache a LoggerMessage action to pass in by calling Define(LogLevel, EventId, string). You can either have a single LoggerMessage definition for all controllers, or have one for each controller. The flexibility is there for you to choose.
viewPolicyName
stringThe policy name to use for Authorization verification.
getViewActionResultAsync
Func<TViewResponseDto, Task<IActionResult>>Task to format the result of CQRS operation into an IActionResult. Allows for controllers to make decisions on what views or data manipulation to carry out.
viewCommandFactoryAsync
Func<TViewRequestDto, ClaimsPrincipal, CancellationToken, Task<TViewQuery>>The Command Factory for the View operation.
cancellationToken
CancellationTokenThe cancellation token for the operation.
Returns
- Task<IActionResult>
A Task<TResult> representing the result of the asynchronous operation.
Type Parameters
TViewRequestDto
The type for the Request DTO for the View Operation.
TViewResponseDto
The type for the Response DTO for the View Operation.
TViewQuery
The type for the CQRS Command for the View Operation.