Class QueryOnlyMvcController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>
- Namespace
- Whipstaff.AspNetCore
- Assembly
- Whipstaff.AspNetCore.dll
A generic MVC controller supporting List and View operations. Pre-defines CQRS activities along with Authorization and logging.
public abstract class QueryOnlyMvcController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions> : Controller, IActionFilter, IAsyncActionFilter, IFilterMetadata, IDisposable where TListQuery : IAuditableRequest<TListRequestDto, TListQueryResponse> where TListRequestDto : class, new() where TListQueryResponse : class where TViewQuery : IAuditableRequest<long, TViewQueryResponse?> where TViewQueryResponse : class where TQueryOnlyControllerLogMessageActions : IQueryOnlyControllerLogMessageActions
Type Parameters
TListQuery
The type for the List Query.
TListRequestDto
The type for the Request DTO for the List Operation.
TListQueryResponse
The type for the Response DTO for the List Operation.
TViewQuery
The type for the View Query.
TViewQueryResponse
The type for the Response DTO for the View Operation.
TQueryOnlyControllerLogMessageActions
The type for the log message actions mapping class.
- Inheritance
-
QueryOnlyMvcController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>
- Implements
- Inherited Members
- Extension Methods
Constructors
QueryOnlyMvcController(IAuthorizationService, ILogger<QueryOnlyMvcController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>>, IMediator, IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse>, TQueryOnlyControllerLogMessageActions)
Initializes a new instance of the QueryOnlyMvcController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions> class.
protected QueryOnlyMvcController(IAuthorizationService authorizationService, ILogger<QueryOnlyMvcController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>> logger, IMediator mediator, IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse> queryFactory, TQueryOnlyControllerLogMessageActions logMessageActionMappings)
Parameters
authorizationService
IAuthorizationServiceThe authorization service for validating access.
logger
ILogger<QueryOnlyMvcController<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse, TQueryOnlyControllerLogMessageActions>>The logger object.
mediator
IMediatorThe mediatr object to publish CQRS messages to.
queryFactory
IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse>The factory for generating Query messages.
logMessageActionMappings
TQueryOnlyControllerLogMessageActionsLog Message Action mappings.
Properties
AuthorizationService
Gets the authorization service instance used to authorize requests.
protected IAuthorizationService AuthorizationService { get; }
Property Value
LogMessageActionMappings
Gets the log message action mappings.
protected TQueryOnlyControllerLogMessageActions LogMessageActionMappings { get; }
Property Value
- TQueryOnlyControllerLogMessageActions
Logger
Gets the logging framework instance.
protected ILogger Logger { get; }
Property Value
Mediator
Gets the Mediator instance used for issuing CQRS messages.
protected IMediator Mediator { get; }
Property Value
- IMediator
QueryFactory
Gets the query factory for creating queries to push through the mediator.
protected IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse> QueryFactory { get; }
Property Value
- IAuditableQueryFactory<TListQuery, TListRequestDto, TListQueryResponse, TViewQuery, TViewQueryResponse>
Methods
GetAsync(long?, CancellationToken)
Entry point for HTTP GET operations.
public Task<IActionResult> GetAsync(long? id, CancellationToken cancellationToken)
Parameters
id
long?unique id of the entity to view. or null if being used to list.
cancellationToken
CancellationTokenCancellation token for the operations.
Returns
- Task<IActionResult>
A Task<TResult> representing the result of the asynchronous operation.
Remarks
Directs requests to List or View operations depending on whether an id is passed.
GetListActionResultAsync(TListQueryResponse)
Gets the Action Result for the List operation.
protected abstract Task<IActionResult> GetListActionResultAsync(TListQueryResponse listResponse)
Parameters
listResponse
TListQueryResponseThe Response DTO from the CQRS operation.
Returns
- Task<IActionResult>
A Task<TResult> representing the result of the asynchronous operation.
GetListPolicyAsync()
Gets the authorization policy for the List operation.
protected abstract Task<string> GetListPolicyAsync()
Returns
- Task<string>
A Task<TResult> representing the result of the asynchronous operation.
GetListQueryAsync(TListRequestDto, ClaimsPrincipal, CancellationToken)
Gets the CQRS List Query.
protected abstract Task<TListQuery> GetListQueryAsync(TListRequestDto listRequestDto, ClaimsPrincipal claimsPrincipal, CancellationToken cancellationToken)
Parameters
listRequestDto
TListRequestDtoThe List Request DTO.
claimsPrincipal
ClaimsPrincipalThe claims principal for the user making the list request.
cancellationToken
CancellationTokenThe cancellation token for the request.
Returns
- Task<TListQuery>
The list query.
GetViewActionResultAsync(TViewQueryResponse)
Gets the Action Result for the View operation.
protected abstract Task<IActionResult> GetViewActionResultAsync(TViewQueryResponse viewResponse)
Parameters
viewResponse
TViewQueryResponseThe Response DTO from the CQRS operation.
Returns
- Task<IActionResult>
A Task<TResult> representing the result of the asynchronous operation.
GetViewPolicyAsync()
Gets the authorization policy for the View operation.
protected abstract Task<string> GetViewPolicyAsync()
Returns
- Task<string>
A Task<TResult> representing the result of the asynchronous operation.
GetViewQueryAsync(long, ClaimsPrincipal, CancellationToken)
Gets CQRS the View Query for the request.
protected abstract Task<TViewQuery> GetViewQueryAsync(long id, ClaimsPrincipal claimsPrincipal, CancellationToken cancellationToken)
Parameters
id
longUnique id of the item to view.
claimsPrincipal
ClaimsPrincipalThe claims principal of the user requesting the view.
cancellationToken
CancellationTokenCancellation token for the request.
Returns
- Task<TViewQuery>
The view query.