| | 1 | | using Fluorite.Strainer.Models.Filtering; |
| | 2 | | using Fluorite.Strainer.Models.Filtering.Operators; |
| | 3 | | using Fluorite.Strainer.Models.Metadata; |
| | 4 | | using Fluorite.Strainer.Models.Sorting; |
| | 5 | |
|
| | 6 | | namespace Fluorite.Strainer.Services.Modules; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// Provides configuration information about metadata, filter operators |
| | 10 | | /// and custom methods for Strainer. |
| | 11 | | /// </summary> |
| | 12 | | /// <typeparam name="T"> |
| | 13 | | /// The type of model for which this module is for. |
| | 14 | | /// </typeparam> |
| | 15 | | public abstract class StrainerModule<T> : IStrainerModule<T>, IStrainerModule |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// Initializes a new instance of the <see cref="StrainerModule{T}"/> class. |
| | 19 | | /// </summary> |
| 1 | 20 | | protected StrainerModule() |
| | 21 | | { |
| 1 | 22 | | CustomFilterMethods = new Dictionary<Type, IDictionary<string, ICustomFilterMethod>>(); |
| 1 | 23 | | CustomSortMethods = new Dictionary<Type, IDictionary<string, ICustomSortMethod>>(); |
| 1 | 24 | | DefaultMetadata = new Dictionary<Type, IPropertyMetadata>(); |
| 1 | 25 | | FilterOperators = new Dictionary<string, IFilterOperator>(); |
| 1 | 26 | | ExcludedBuiltInFilterOperators = new HashSet<string>(); |
| 1 | 27 | | ObjectMetadata = new Dictionary<Type, IObjectMetadata>(); |
| 1 | 28 | | PropertyMetadata = new Dictionary<Type, IDictionary<string, IPropertyMetadata>>(); |
| 1 | 29 | | } |
| | 30 | |
|
| | 31 | | /// <inheritdoc/> |
| 1 | 32 | | public IDictionary<Type, IDictionary<string, ICustomFilterMethod>> CustomFilterMethods { get; } |
| | 33 | |
|
| | 34 | | /// <inheritdoc/> |
| 1 | 35 | | public IDictionary<Type, IDictionary<string, ICustomSortMethod>> CustomSortMethods { get; } |
| | 36 | |
|
| | 37 | | /// <inheritdoc/> |
| 1 | 38 | | public IDictionary<Type, IPropertyMetadata> DefaultMetadata { get; } |
| | 39 | |
|
| | 40 | | /// <inheritdoc/> |
| 1 | 41 | | public IDictionary<string, IFilterOperator> FilterOperators { get; } |
| | 42 | |
|
| | 43 | | /// <inheritdoc/> |
| 1 | 44 | | public ISet<string> ExcludedBuiltInFilterOperators { get; } |
| | 45 | |
|
| | 46 | | /// <inheritdoc/> |
| 2 | 47 | | public IDictionary<Type, IObjectMetadata> ObjectMetadata { get; } |
| | 48 | |
|
| | 49 | | /// <inheritdoc/> |
| 1 | 50 | | public IDictionary<Type, IDictionary<string, IPropertyMetadata>> PropertyMetadata { get; } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Loads configuration in module. |
| | 54 | | /// <para/> |
| | 55 | | /// Override this method to specify configuration for this module. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name="builder"> |
| | 58 | | /// The Strainer Module builder. |
| | 59 | | /// </param> |
| | 60 | | public abstract void Load(IStrainerModuleBuilder<T> builder); |
| | 61 | |
|
| | 62 | | /// <inheritdoc/> |
| | 63 | | public void Load(IStrainerModuleBuilder builder) |
| | 64 | | { |
| 0 | 65 | | Guard.Against.Null(builder); |
| | 66 | |
|
| 0 | 67 | | if (builder is not IStrainerModuleBuilder<T> typedBuilder) |
| | 68 | | { |
| 0 | 69 | | throw new NotSupportedException("Only strongly typed module builder is supported."); |
| | 70 | | } |
| | 71 | |
|
| 0 | 72 | | Load(typedBuilder); |
| 0 | 73 | | } |
| | 74 | | } |