| | | 1 | | namespace ZhEaIsNsAaBn.Infrastructure.Specifications; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Base for projecting specifications: an Ardalis <see cref="Specification{T, TResult}"/> (call <c>Query.Select( … )</c |
| | | 5 | | /// constructor) that can reject its own filter. Set <see cref="IsValid"/> to a failure and the repository returns it wi |
| | | 6 | | /// </summary> |
| | | 7 | | /// <typeparam name="TEntity">The entity type.</typeparam> |
| | | 8 | | /// <typeparam name="TResult">The read model the rows are projected to.</typeparam> |
| | | 9 | | public abstract class BaseSpecification< TEntity, TResult > : Specification<TEntity, TResult> |
| | | 10 | | where TEntity : class |
| | | 11 | | { |
| | | 12 | | /// <summary>Success, or the reasons the filter is invalid.</summary> |
| | | 13 | | public LayerResponse IsValid { get; protected set; } = LayerResponse.Success(); |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | /// <summary>A no-tracking projected list query; derive, add criteria and <c>Query.Select( … )</c>.</summary> |
| | | 17 | | /// <typeparam name="TEntity">The entity type.</typeparam> |
| | | 18 | | /// <typeparam name="TResult">The read model.</typeparam> |
| | | 19 | | public abstract class ListSpecification< TEntity, TResult > : BaseSpecification<TEntity, TResult> |
| | | 20 | | where TEntity : class |
| | | 21 | | { |
| | | 22 | | /// <summary>Creates the specification.</summary> |
| | | 23 | | /// <param name="filter">The list filter.</param> |
| | | 24 | | protected ListSpecification( IListFilter<TEntity> filter ) => Query.AsNoTracking(); |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary>A projected single-row query, no-tracking unless the filter asks for tracking; derive, add criteria and <c> |
| | | 28 | | /// <typeparam name="TEntity">The entity type.</typeparam> |
| | | 29 | | /// <typeparam name="TResult">The read model.</typeparam> |
| | | 30 | | public abstract class SingleSpecification< TEntity, TResult > : BaseSpecification<TEntity, TResult> |
| | | 31 | | where TEntity : class |
| | | 32 | | { |
| | | 33 | | /// <summary>Creates the specification.</summary> |
| | | 34 | | /// <param name="filter">The filter.</param> |
| | | 35 | | /// <exception cref="ArgumentNullException"><paramref name="filter"/> is <see langword="null"/>.</exception> |
| | 28 | 36 | | protected SingleSpecification( ISingleFilter<TEntity> filter ) |
| | | 37 | | { |
| | 28 | 38 | | ArgumentNullException.ThrowIfNull( filter ); |
| | | 39 | | |
| | 56 | 40 | | if ( filter.AsNoTracking ) { Query.AsNoTracking(); } |
| | 28 | 41 | | } |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary>A no-tracking projected page query (see <see cref="PaginationExtensions.Pagination{TEntity}"/>); derive, ad |
| | | 45 | | /// <typeparam name="TEntity">The entity type.</typeparam> |
| | | 46 | | /// <typeparam name="TResult">The read model.</typeparam> |
| | | 47 | | public abstract class PaginationSpecification< TEntity, TResult > : BaseSpecification<TEntity, TResult> |
| | | 48 | | where TEntity : class |
| | | 49 | | { |
| | | 50 | | /// <summary>Creates the specification.</summary> |
| | | 51 | | /// <param name="filter">The page request.</param> |
| | | 52 | | protected PaginationSpecification( IPaginationFilter<TEntity> filter ) => Query.AsNoTracking().Pagination( filter ); |
| | | 53 | | } |