| | 1 | | using Fluorite.Strainer.AspNetCore.Services; |
| | 2 | | using Fluorite.Strainer.Models; |
| | 3 | | using Fluorite.Strainer.Services; |
| | 4 | | using Fluorite.Strainer.Services.Configuration; |
| | 5 | | using Fluorite.Strainer.Services.Conversion; |
| | 6 | | using Fluorite.Strainer.Services.Filtering; |
| | 7 | | using Fluorite.Strainer.Services.Filtering.Steps; |
| | 8 | | using Fluorite.Strainer.Services.Linq; |
| | 9 | | using Fluorite.Strainer.Services.Metadata; |
| | 10 | | using Fluorite.Strainer.Services.Metadata.Attributes; |
| | 11 | | using Fluorite.Strainer.Services.Metadata.FluentApi; |
| | 12 | | using Fluorite.Strainer.Services.Modules; |
| | 13 | | using Fluorite.Strainer.Services.Pagination; |
| | 14 | | using Fluorite.Strainer.Services.Pipelines; |
| | 15 | | using Fluorite.Strainer.Services.Sorting; |
| | 16 | | using Fluorite.Strainer.Services.Validation; |
| | 17 | | using Microsoft.Extensions.Configuration; |
| | 18 | | using Microsoft.Extensions.DependencyInjection; |
| | 19 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | 20 | | using System.Reflection; |
| | 21 | |
|
| | 22 | | namespace Fluorite.Extensions.DependencyInjection; |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Provides extensions for adding Strainer services to <see cref="IServiceCollection"/>. |
| | 26 | | /// </summary> |
| | 27 | | public static class StrainerServiceCollectionExtensions |
| | 28 | | { |
| | 29 | | /// <summary> |
| | 30 | | /// The default service lifetime for Strainer services. |
| | 31 | | /// </summary> |
| | 32 | | public const ServiceLifetime DefaultServiceLifetime = ServiceLifetime.Scoped; |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Adds Strainer services to the <see cref="IServiceCollection"/>. |
| | 36 | | /// </summary> |
| | 37 | | /// <param name="services"> |
| | 38 | | /// Current instance of <see cref="IServiceCollection"/>. |
| | 39 | | /// </param> |
| | 40 | | /// <param name="serviceLifetime"> |
| | 41 | | /// The service lifetime for Strainer services. |
| | 42 | | /// </param> |
| | 43 | | /// <returns> |
| | 44 | | /// An instance of <see cref="IServiceCollection"/> with added |
| | 45 | | /// Strainer services, so additional calls can be chained. |
| | 46 | | /// </returns> |
| | 47 | | /// <exception cref="ArgumentNullException"> |
| | 48 | | /// <paramref name="services"/> is <see langword="null"/>. |
| | 49 | | /// </exception> |
| | 50 | | public static IServiceCollection AddStrainer( |
| | 51 | | this IServiceCollection services, |
| | 52 | | ServiceLifetime serviceLifetime = DefaultServiceLifetime) |
| | 53 | | { |
| 10 | 54 | | Guard.Against.Null(services); |
| | 55 | |
|
| 10 | 56 | | return services.AddStrainer(new List<Type>(), serviceLifetime); |
| | 57 | | } |
| | 58 | |
|
| | 59 | | /// <summary> |
| | 60 | | /// Adds Strainer services to the <see cref="IServiceCollection"/> |
| | 61 | | /// with a collection of assemblies containing Strainer module types. |
| | 62 | | /// </summary> |
| | 63 | | /// <param name="services"> |
| | 64 | | /// Current instance of <see cref="IServiceCollection"/>. |
| | 65 | | /// </param> |
| | 66 | | /// <param name="assembliesToScan"> |
| | 67 | | /// Assemblies that will be scanned in search for non-abstract classes |
| | 68 | | /// deriving from <see cref="StrainerModule"/>. Matching classes will |
| | 69 | | /// be added to Strainer as configuration modules. |
| | 70 | | /// <para /> |
| | 71 | | /// Referenced assemblies will not be included. |
| | 72 | | /// </param> |
| | 73 | | /// <param name="serviceLifetime"> |
| | 74 | | /// The service lifetime for Strainer services. |
| | 75 | | /// </param> |
| | 76 | | /// <returns> |
| | 77 | | /// An instance of <see cref="IServiceCollection"/> with added |
| | 78 | | /// Strainer services, so additional calls can be chained. |
| | 79 | | /// </returns> |
| | 80 | | /// <exception cref="ArgumentNullException"> |
| | 81 | | /// <paramref name="services"/> is <see langword="null"/>. |
| | 82 | | /// </exception> |
| | 83 | | /// <exception cref="ArgumentNullException"> |
| | 84 | | /// <paramref name="assembliesToScan"/> is <see langword="null"/>. |
| | 85 | | /// </exception> |
| | 86 | | public static IServiceCollection AddStrainer( |
| | 87 | | this IServiceCollection services, |
| | 88 | | Assembly[] assembliesToScan, |
| | 89 | | ServiceLifetime serviceLifetime = DefaultServiceLifetime) |
| | 90 | | { |
| 3 | 91 | | Guard.Against.Null(services); |
| 3 | 92 | | Guard.Against.Null(assembliesToScan); |
| | 93 | |
|
| 3 | 94 | | var moduleTypes = GetModuleTypesFromAssemblies(assembliesToScan); |
| | 95 | |
|
| 3 | 96 | | services.TryAddSingleton<IMetadataAssemblySourceProvider>(new AssemblySourceProvider(assembliesToScan)); |
| | 97 | |
|
| 3 | 98 | | return services.AddStrainer(moduleTypes, serviceLifetime); |
| | 99 | | } |
| | 100 | |
|
| | 101 | | /// <summary> |
| | 102 | | /// Adds Strainer services to the <see cref="IServiceCollection"/> |
| | 103 | | /// with a collection of Strainer module types. |
| | 104 | | /// </summary> |
| | 105 | | /// <param name="services"> |
| | 106 | | /// Current instance of <see cref="IServiceCollection"/>. |
| | 107 | | /// </param> |
| | 108 | | /// <param name="moduleTypes"> |
| | 109 | | /// The types of Strainer modules. |
| | 110 | | /// </param> |
| | 111 | | /// <param name="serviceLifetime"> |
| | 112 | | /// The service lifetime for Strainer services. |
| | 113 | | /// </param> |
| | 114 | | /// <returns> |
| | 115 | | /// An instance of <see cref="IServiceCollection"/> with added |
| | 116 | | /// Strainer services, so additional calls can be chained. |
| | 117 | | /// </returns> |
| | 118 | | /// <exception cref="ArgumentNullException"> |
| | 119 | | /// <paramref name="services"/> is <see langword="null"/>. |
| | 120 | | /// </exception> |
| | 121 | | /// <exception cref="ArgumentNullException"> |
| | 122 | | /// <paramref name="moduleTypes"/> is <see langword="null"/>. |
| | 123 | | /// </exception> |
| | 124 | | public static IServiceCollection AddStrainer( |
| | 125 | | this IServiceCollection services, |
| | 126 | | IReadOnlyCollection<Type> moduleTypes, |
| | 127 | | ServiceLifetime serviceLifetime = DefaultServiceLifetime) |
| | 128 | | { |
| 20 | 129 | | Guard.Against.Null(services); |
| 20 | 130 | | Guard.Against.Null(moduleTypes); |
| | 131 | |
|
| 20 | 132 | | RegisterStrainerServices(services, moduleTypes, serviceLifetime); |
| | 133 | |
|
| 20 | 134 | | return services; |
| | 135 | | } |
| | 136 | |
|
| | 137 | | /// <summary> |
| | 138 | | /// Adds Strainer services to the <see cref="IServiceCollection"/> |
| | 139 | | /// with a configuration. |
| | 140 | | /// </summary> |
| | 141 | | /// <param name="services"> |
| | 142 | | /// Current instance of <see cref="IServiceCollection"/>. |
| | 143 | | /// </param> |
| | 144 | | /// <param name="configuration"> |
| | 145 | | /// A configuration used to bind against <see cref="StrainerOptions"/>. |
| | 146 | | /// </param> |
| | 147 | | /// <param name="serviceLifetime"> |
| | 148 | | /// The service lifetime for Strainer services. |
| | 149 | | /// </param> |
| | 150 | | /// <returns> |
| | 151 | | /// An instance of <see cref="IServiceCollection"/> with added |
| | 152 | | /// Strainer services, so additional calls can be chained. |
| | 153 | | /// </returns> |
| | 154 | | /// <exception cref="ArgumentNullException"> |
| | 155 | | /// <paramref name="services"/> is <see langword="null"/>. |
| | 156 | | /// </exception> |
| | 157 | | /// <exception cref="ArgumentNullException"> |
| | 158 | | /// <paramref name="configuration"/> is <see langword="null"/>. |
| | 159 | | /// </exception> |
| | 160 | | public static IServiceCollection AddStrainer( |
| | 161 | | this IServiceCollection services, |
| | 162 | | IConfiguration configuration, |
| | 163 | | ServiceLifetime serviceLifetime = DefaultServiceLifetime) |
| | 164 | | { |
| 1 | 165 | | Guard.Against.Null(services); |
| 1 | 166 | | Guard.Against.Null(configuration); |
| | 167 | |
|
| 1 | 168 | | return services.AddStrainer(configuration, new List<Type>(), serviceLifetime); |
| | 169 | | } |
| | 170 | |
|
| | 171 | | /// <summary> |
| | 172 | | /// Adds Strainer services to the <see cref="IServiceCollection"/> |
| | 173 | | /// with a configuration and a collection of Strainer module types. |
| | 174 | | /// </summary> |
| | 175 | | /// <param name="services"> |
| | 176 | | /// Current instance of <see cref="IServiceCollection"/>. |
| | 177 | | /// </param> |
| | 178 | | /// <param name="configuration"> |
| | 179 | | /// A configuration used to bind against <see cref="StrainerOptions"/>. |
| | 180 | | /// </param> |
| | 181 | | /// <param name="moduleTypes"> |
| | 182 | | /// The types of Strainer modules. |
| | 183 | | /// </param> |
| | 184 | | /// <param name="serviceLifetime"> |
| | 185 | | /// The service lifetime for Strainer services. |
| | 186 | | /// </param> |
| | 187 | | /// <returns> |
| | 188 | | /// An instance of <see cref="IServiceCollection"/> with added |
| | 189 | | /// Strainer services, so additional calls can be chained. |
| | 190 | | /// </returns> |
| | 191 | | /// <exception cref="ArgumentNullException"> |
| | 192 | | /// <paramref name="services"/> is <see langword="null"/>. |
| | 193 | | /// </exception> |
| | 194 | | /// <exception cref="ArgumentNullException"> |
| | 195 | | /// <paramref name="configuration"/> is <see langword="null"/>. |
| | 196 | | /// </exception> |
| | 197 | | /// <exception cref="ArgumentNullException"> |
| | 198 | | /// <paramref name="moduleTypes"/> is <see langword="null"/>. |
| | 199 | | /// </exception> |
| | 200 | | public static IServiceCollection AddStrainer( |
| | 201 | | this IServiceCollection services, |
| | 202 | | IConfiguration configuration, |
| | 203 | | IReadOnlyCollection<Type> moduleTypes, |
| | 204 | | ServiceLifetime serviceLifetime = DefaultServiceLifetime) |
| | 205 | | { |
| 1 | 206 | | Guard.Against.Null(services); |
| 1 | 207 | | Guard.Against.Null(configuration); |
| 1 | 208 | | Guard.Against.Null(moduleTypes); |
| | 209 | |
|
| 1 | 210 | | services.Configure<StrainerOptions>(configuration); |
| | 211 | |
|
| 1 | 212 | | return services.AddStrainer(moduleTypes, serviceLifetime); |
| | 213 | | } |
| | 214 | |
|
| | 215 | | /// <summary> |
| | 216 | | /// Adds Strainer services to the <see cref="IServiceCollection"/> |
| | 217 | | /// with a configuration and a collection of assemblies containing |
| | 218 | | /// Strainer module types. |
| | 219 | | /// </summary> |
| | 220 | | /// <param name="services"> |
| | 221 | | /// Current instance of <see cref="IServiceCollection"/>. |
| | 222 | | /// </param> |
| | 223 | | /// <param name="configuration"> |
| | 224 | | /// A configuration used to bind against <see cref="StrainerOptions"/>. |
| | 225 | | /// </param> |
| | 226 | | /// <param name="assembliesToScan"> |
| | 227 | | /// Assemblies that will be scanned in search for non-abstract classes |
| | 228 | | /// deriving from <see cref="StrainerModule"/>. Matching classes will |
| | 229 | | /// be added to Strainer as configuration modules. |
| | 230 | | /// <para /> |
| | 231 | | /// Referenced assemblies will not be included. |
| | 232 | | /// </param> |
| | 233 | | /// <param name="serviceLifetime"> |
| | 234 | | /// The service lifetime for Strainer services. |
| | 235 | | /// </param> |
| | 236 | | /// <returns> |
| | 237 | | /// An instance of <see cref="IServiceCollection"/> with added |
| | 238 | | /// Strainer services, so additional calls can be chained. |
| | 239 | | /// </returns> |
| | 240 | | /// <exception cref="ArgumentNullException"> |
| | 241 | | /// <paramref name="services"/> is <see langword="null"/>. |
| | 242 | | /// </exception> |
| | 243 | | /// <exception cref="ArgumentNullException"> |
| | 244 | | /// <paramref name="configuration"/> is <see langword="null"/>. |
| | 245 | | /// </exception> |
| | 246 | | /// <exception cref="ArgumentNullException"> |
| | 247 | | /// <paramref name="assembliesToScan"/> is <see langword="null"/>. |
| | 248 | | /// </exception> |
| | 249 | | public static IServiceCollection AddStrainer( |
| | 250 | | this IServiceCollection services, |
| | 251 | | IConfiguration configuration, |
| | 252 | | Assembly[] assembliesToScan, |
| | 253 | | ServiceLifetime serviceLifetime = DefaultServiceLifetime) |
| | 254 | | { |
| 1 | 255 | | Guard.Against.Null(services); |
| 1 | 256 | | Guard.Against.Null(configuration); |
| 1 | 257 | | Guard.Against.Null(assembliesToScan); |
| | 258 | |
|
| 1 | 259 | | services.Configure<StrainerOptions>(configuration); |
| 1 | 260 | | services.TryAddSingleton<IMetadataAssemblySourceProvider>(new AssemblySourceProvider(assembliesToScan)); |
| | 261 | |
|
| 1 | 262 | | return services.AddStrainer(assembliesToScan, serviceLifetime); |
| | 263 | | } |
| | 264 | |
|
| | 265 | | /// <summary> |
| | 266 | | /// Adds Strainer services to the <see cref="IServiceCollection"/> |
| | 267 | | /// with a configuration action. |
| | 268 | | /// </summary> |
| | 269 | | /// <param name="services"> |
| | 270 | | /// Current instance of <see cref="IServiceCollection"/>. |
| | 271 | | /// </param> |
| | 272 | | /// <param name="configure"> |
| | 273 | | /// An action used to configure <see cref="StrainerOptions"/>. |
| | 274 | | /// </param> |
| | 275 | | /// <param name="serviceLifetime"> |
| | 276 | | /// The service lifetime for Strainer services. |
| | 277 | | /// </param> |
| | 278 | | /// <returns> |
| | 279 | | /// An instance of <see cref="IServiceCollection"/> with added |
| | 280 | | /// Strainer services, so additional calls can be chained. |
| | 281 | | /// </returns> |
| | 282 | | /// <exception cref="ArgumentNullException"> |
| | 283 | | /// <paramref name="services"/> is <see langword="null"/>. |
| | 284 | | /// </exception> |
| | 285 | | /// <exception cref="ArgumentNullException"> |
| | 286 | | /// <paramref name="configure"/> is <see langword="null"/>. |
| | 287 | | /// </exception> |
| | 288 | | public static IServiceCollection AddStrainer( |
| | 289 | | this IServiceCollection services, |
| | 290 | | Action<StrainerOptions> configure, |
| | 291 | | ServiceLifetime serviceLifetime = DefaultServiceLifetime) |
| | 292 | | { |
| 1 | 293 | | Guard.Against.Null(services); |
| 1 | 294 | | Guard.Against.Null(configure); |
| | 295 | |
|
| 1 | 296 | | return services.AddStrainer(configure, new List<Type>(), serviceLifetime); |
| | 297 | | } |
| | 298 | |
|
| | 299 | | /// <summary> |
| | 300 | | /// Adds Strainer services to the <see cref="IServiceCollection"/> |
| | 301 | | /// with a configuration action and a collection of Strainer module types. |
| | 302 | | /// </summary> |
| | 303 | | /// <param name="services"> |
| | 304 | | /// Current instance of <see cref="IServiceCollection"/>. |
| | 305 | | /// </param> |
| | 306 | | /// <param name="configure"> |
| | 307 | | /// An action used to configure <see cref="StrainerOptions"/>. |
| | 308 | | /// </param> |
| | 309 | | /// <param name="moduleTypes"> |
| | 310 | | /// The types of Strainer modules. |
| | 311 | | /// </param> |
| | 312 | | /// <param name="serviceLifetime"> |
| | 313 | | /// The service lifetime for Strainer services. |
| | 314 | | /// </param> |
| | 315 | | /// <returns> |
| | 316 | | /// An instance of <see cref="IServiceCollection"/> with added |
| | 317 | | /// Strainer services, so additional calls can be chained. |
| | 318 | | /// </returns> |
| | 319 | | /// <exception cref="ArgumentNullException"> |
| | 320 | | /// <paramref name="services"/> is <see langword="null"/>. |
| | 321 | | /// </exception> |
| | 322 | | /// <exception cref="ArgumentNullException"> |
| | 323 | | /// <paramref name="configure"/> is <see langword="null"/>. |
| | 324 | | /// </exception> |
| | 325 | | /// <exception cref="ArgumentNullException"> |
| | 326 | | /// <paramref name="moduleTypes"/> is <see langword="null"/>. |
| | 327 | | /// </exception> |
| | 328 | | public static IServiceCollection AddStrainer( |
| | 329 | | this IServiceCollection services, |
| | 330 | | Action<StrainerOptions> configure, |
| | 331 | | IReadOnlyCollection<Type> moduleTypes, |
| | 332 | | ServiceLifetime serviceLifetime = DefaultServiceLifetime) |
| | 333 | | { |
| 1 | 334 | | Guard.Against.Null(services); |
| 1 | 335 | | Guard.Against.Null(configure); |
| 1 | 336 | | Guard.Against.Null(moduleTypes); |
| | 337 | |
|
| 1 | 338 | | services.AddOptions<StrainerOptions>().Configure(configure); |
| | 339 | |
|
| 1 | 340 | | return services.AddStrainer(moduleTypes, serviceLifetime); |
| | 341 | | } |
| | 342 | |
|
| | 343 | | /// <summary> |
| | 344 | | /// Adds Strainer services to the <see cref="IServiceCollection"/> |
| | 345 | | /// with a configuration action and a collection of assemblies containing |
| | 346 | | /// Strainer module types. |
| | 347 | | /// </summary> |
| | 348 | | /// <param name="services"> |
| | 349 | | /// Current instance of <see cref="IServiceCollection"/>. |
| | 350 | | /// </param> |
| | 351 | | /// <param name="configure"> |
| | 352 | | /// An action used to configure <see cref="StrainerOptions"/>. |
| | 353 | | /// </param> |
| | 354 | | /// <param name="assembliesToScan"> |
| | 355 | | /// Assemblies that will be scanned in search for non-abstract classes |
| | 356 | | /// deriving from <see cref="StrainerModule"/>. Matching classes will |
| | 357 | | /// be added to Strainer as configuration modules. |
| | 358 | | /// <para /> |
| | 359 | | /// Referenced assemblies will not be included. |
| | 360 | | /// </param> |
| | 361 | | /// <param name="serviceLifetime"> |
| | 362 | | /// The service lifetime for Strainer services. |
| | 363 | | /// </param> |
| | 364 | | /// <returns> |
| | 365 | | /// An instance of <see cref="IServiceCollection"/> with added |
| | 366 | | /// Strainer services, so additional calls can be chained. |
| | 367 | | /// </returns> |
| | 368 | | /// <exception cref="ArgumentNullException"> |
| | 369 | | /// <paramref name="services"/> is <see langword="null"/>. |
| | 370 | | /// </exception> |
| | 371 | | /// <exception cref="ArgumentNullException"> |
| | 372 | | /// <paramref name="configure"/> is <see langword="null"/>. |
| | 373 | | /// </exception> |
| | 374 | | /// <exception cref="ArgumentNullException"> |
| | 375 | | /// <paramref name="assembliesToScan"/> is <see langword="null"/>. |
| | 376 | | /// </exception> |
| | 377 | | public static IServiceCollection AddStrainer( |
| | 378 | | this IServiceCollection services, |
| | 379 | | Action<StrainerOptions> configure, |
| | 380 | | Assembly[] assembliesToScan, |
| | 381 | | ServiceLifetime serviceLifetime = DefaultServiceLifetime) |
| | 382 | | { |
| 1 | 383 | | Guard.Against.Null(services); |
| 1 | 384 | | Guard.Against.Null(configure); |
| 1 | 385 | | Guard.Against.Null(assembliesToScan); |
| | 386 | |
|
| 1 | 387 | | services.AddOptions<StrainerOptions>().Configure(configure); |
| 1 | 388 | | services.TryAddSingleton<IMetadataAssemblySourceProvider>(new AssemblySourceProvider(assembliesToScan)); |
| | 389 | |
|
| 1 | 390 | | return services.AddStrainer(assembliesToScan, serviceLifetime); |
| | 391 | | } |
| | 392 | |
|
| | 393 | | private static void RegisterStrainerServices( |
| | 394 | | IServiceCollection services, |
| | 395 | | IReadOnlyCollection<Type> moduleTypes, |
| | 396 | | ServiceLifetime serviceLifetime) |
| | 397 | | { |
| 20 | 398 | | services.AddOptions<StrainerOptions>(); |
| | 399 | |
|
| 20 | 400 | | if (serviceLifetime == ServiceLifetime.Singleton) |
| | 401 | | { |
| 1 | 402 | | services.TryAdd<IStrainerOptionsProvider, AspNetCoreSingletonStrainerOptionsProvider>(serviceLifetime); |
| | 403 | | } |
| | 404 | | else |
| | 405 | | { |
| 19 | 406 | | services.TryAdd<IStrainerOptionsProvider, AspNetCoreStrainerOptionsProvider>(serviceLifetime); |
| | 407 | | } |
| | 408 | |
|
| 20 | 409 | | services.TryAdd<IQueryableEvaluator, QueryableEvaluator>(serviceLifetime); |
| 20 | 410 | | services.TryAdd<IFilterExpressionProvider, FilterExpressionProvider>(serviceLifetime); |
| 20 | 411 | | services.TryAdd<IFilterOperatorParser, FilterOperatorParser>(serviceLifetime); |
| 20 | 412 | | services.TryAdd<IFilterOperatorValidator, FilterOperatorValidator>(serviceLifetime); |
| 20 | 413 | | services.TryAdd<IFilterTermNamesParser, FilterTermNamesParser>(serviceLifetime); |
| 20 | 414 | | services.TryAdd<IFilterTermValuesParser, FilterTermValuesParser>(serviceLifetime); |
| 20 | 415 | | services.TryAdd<IFilterTermSectionsParser, FilterTermSectionsParser>(serviceLifetime); |
| 20 | 416 | | services.TryAdd<IFilterTermParser, FilterTermParser>(serviceLifetime); |
| 20 | 417 | | services.TryAdd<ICustomFilteringExpressionProvider, CustomFilteringExpressionProvider>(serviceLifetime); |
| 20 | 418 | | services.TryAdd<IFilterExpressionWorkflowBuilder, FilterExpressionWorkflowBuilder>(serviceLifetime); |
| 20 | 419 | | services.TryAdd<IConvertPropertyValueToStringStep, ConvertPropertyValueToStringStep>(serviceLifetime); |
| 20 | 420 | | services.TryAdd<IConvertFilterValueToStringStep, ConvertFilterValueToStringStep>(serviceLifetime); |
| 20 | 421 | | services.TryAdd<IChangeTypeOfFilterValueStep, ChangeTypeOfFilterValueStep>(serviceLifetime); |
| 20 | 422 | | services.TryAdd<IApplyConsantClosureToFilterValueStep, ApplyConsantClosureToFilterValueStep>(serviceLifetime); |
| 20 | 423 | | services.TryAdd<IMitigateCaseInsensitivityStep, MitigateCaseInsensitivityStep>(serviceLifetime); |
| 20 | 424 | | services.TryAdd<IApplyFilterOperatorStep, ApplyFilterOperatorStep>(serviceLifetime); |
| 20 | 425 | | services.TryAdd<IFilterContext, FilterContext>(serviceLifetime); |
| | 426 | |
|
| 20 | 427 | | services.TryAdd<ISortExpressionProvider, SortExpressionProvider>(serviceLifetime); |
| 20 | 428 | | services.TryAdd<ISortExpressionValidator, SortExpressionValidator>(serviceLifetime); |
| 20 | 429 | | services.TryAdd<ISortingWayFormatter, DescendingPrefixSortingWayFormatter>(serviceLifetime); |
| 20 | 430 | | services.TryAdd<ISortTermValueParser, SortTermValueParser>(serviceLifetime); |
| 20 | 431 | | services.TryAdd<ISortTermParser, SortTermParser>(serviceLifetime); |
| 20 | 432 | | services.TryAdd<ISortingApplier, SortingApplier>(serviceLifetime); |
| 20 | 433 | | services.TryAdd<ICustomSortingExpressionProvider, CustomSortingExpressionProvider>(serviceLifetime); |
| 20 | 434 | | services.TryAdd<ISortingContext, SortingContext>(serviceLifetime); |
| 20 | 435 | | services.TryAdd<IPipelineContext, PipelineContext>(serviceLifetime); |
| | 436 | |
|
| 20 | 437 | | services.TryAdd<IPageNumberEvaluator, PageNumberEvaluator>(serviceLifetime); |
| 20 | 438 | | services.TryAdd<IPageSizeEvaluator, PageSizeEvaluator>(serviceLifetime); |
| | 439 | |
|
| 20 | 440 | | services.TryAdd<IStrainerPipelineBuilderFactory, StrainerPipelineBuilderFactory>(serviceLifetime); |
| 20 | 441 | | services.TryAdd<IFilterPipelineOperation, FilterPipelineOperation>(serviceLifetime); |
| 20 | 442 | | services.TryAdd<ISortPipelineOperation, SortPipelineOperation>(serviceLifetime); |
| 20 | 443 | | services.TryAdd<IPaginatePipelineOperation, PaginatePipelineOperation>(serviceLifetime); |
| | 444 | |
|
| 20 | 445 | | services.TryAddSingleton<IMetadataAssemblySourceProvider, AppDomainAssemblySourceProvider>(); |
| 20 | 446 | | services.TryAdd<IMetadataSourceTypeProvider, MetadataSourceTypeProvider>(serviceLifetime); |
| | 447 | |
|
| 20 | 448 | | services.TryAdd<IAttributePropertyMetadataBuilder, AttributePropertyMetadataBuilder>(serviceLifetime); |
| 20 | 449 | | services.TryAdd<IAttributeMetadataRetriever, AttributeMetadataRetriever>(serviceLifetime); |
| 20 | 450 | | services.TryAdd<IAttributeCriteriaChecker, AttributeCriteriaChecker>(serviceLifetime); |
| 20 | 451 | | services.TryAdd<IStrainerAttributeProvider, StrainerAttributeProvider>(serviceLifetime); |
| 20 | 452 | | services.TryAdd<IPropertyMetadataDictionaryProvider, PropertyMetadataDictionaryProvider>(serviceLifetime); |
| 20 | 453 | | services.TryAdd<IPropertyInfoProvider, PropertyInfoProvider>(serviceLifetime); |
| 20 | 454 | | services.TryAdd<IMetadataSourceChecker, MetadataSourceChecker>(serviceLifetime); |
| 20 | 455 | | services.TryAdd<IFluentApiPropertyMetadataBuilder, FluentApiPropertyMetadataBuilder>(serviceLifetime); |
| 20 | 456 | | services.TryAddEnumerable<IMetadataProvider, FluentApiMetadataProvider>(serviceLifetime); |
| 20 | 457 | | services.TryAddEnumerable<IMetadataProvider, AttributeMetadataProvider>(serviceLifetime); |
| 20 | 458 | | services.TryAdd<IMetadataFacade, MetadataFacade>(serviceLifetime); |
| | 459 | |
|
| 20 | 460 | | services.TryAdd<ITypeConverterProvider, TypeConverterProvider>(serviceLifetime); |
| 20 | 461 | | services.TryAdd<IStringValueConverter, StringValueConverter>(serviceLifetime); |
| 20 | 462 | | services.TryAdd<ITypeChanger, TypeChanger>(serviceLifetime); |
| | 463 | |
|
| 20 | 464 | | services.TryAdd<IStrainerConfigurationFactory, StrainerConfigurationFactory>(serviceLifetime); |
| 20 | 465 | | services.TryAdd<IStrainerModuleFactory, StrainerModuleFactory>(serviceLifetime); |
| 20 | 466 | | services.TryAdd<IStrainerModuleLoader, StrainerModuleLoader>(serviceLifetime); |
| 20 | 467 | | services.TryAdd<IModuleLoadingStrategySelector, ModuleLoadingStrategySelector>(serviceLifetime); |
| 20 | 468 | | services.TryAdd<IPlainModuleLoadingStrategy, PlainModuleLoadingStrategy>(serviceLifetime); |
| 20 | 469 | | services.TryAdd<IGenericModuleLoadingStrategy, GenericModuleLoadingStrategy>(serviceLifetime); |
| 20 | 470 | | services.TryAdd<IStrainerModuleBuilderFactory, StrainerModuleBuilderFactory>(serviceLifetime); |
| 20 | 471 | | services.TryAdd<IStrainerModuleTypeValidator, StrainerModuleTypeValidator>(serviceLifetime); |
| 20 | 472 | | services.TryAdd<IStrainerConfigurationValidator, StrainerConfigurationValidator>(serviceLifetime); |
| 20 | 473 | | services.TryAdd<IConfigurationCustomMethodsProvider, ConfigurationCustomMethodsProvider>(serviceLifetime); |
| 20 | 474 | | services.TryAdd<IConfigurationFilterOperatorsProvider, ConfigurationFilterOperatorsProvider>(serviceLifetime); |
| 20 | 475 | | services.TryAdd<IConfigurationMetadataProvider, ConfigurationMetadataProvider>(serviceLifetime); |
| | 476 | |
|
| 20 | 477 | | services.TryAdd<IStrainerContext, StrainerContext>(serviceLifetime); |
| 20 | 478 | | services.TryAdd<IStrainerProcessor, StrainerProcessor>(serviceLifetime); |
| | 479 | |
|
| 20 | 480 | | services.TryAddSingleton<IStrainerConfigurationProvider>(serviceProvider => |
| 20 | 481 | | { |
| 10 | 482 | | using var scope = serviceProvider.CreateScope(); |
| 10 | 483 | | var configurationFactory = scope.ServiceProvider.GetRequiredService<IStrainerConfigurationFactory>(); |
| 10 | 484 | | var configurationValidator = scope.ServiceProvider.GetRequiredService<IStrainerConfigurationValidator>(); |
| 20 | 485 | |
|
| 20 | 486 | | try |
| 20 | 487 | | { |
| 10 | 488 | | var strainerConfiguration = configurationFactory.Create(moduleTypes); |
| 8 | 489 | | configurationValidator.Validate(strainerConfiguration); |
| 20 | 490 | |
|
| 8 | 491 | | return new StrainerConfigurationProvider(strainerConfiguration); |
| 20 | 492 | | } |
| 2 | 493 | | catch (Exception ex) |
| 20 | 494 | | { |
| 2 | 495 | | throw new InvalidOperationException("Unable to add configuration from Strainer modules.", ex); |
| 20 | 496 | | } |
| 28 | 497 | | }); |
| 20 | 498 | | } |
| | 499 | |
|
| | 500 | | private static void TryAdd<TServiceType, TImplementationType>( |
| | 501 | | this IServiceCollection services, |
| | 502 | | ServiceLifetime serviceLifetime) |
| | 503 | | where TImplementationType : TServiceType |
| | 504 | | { |
| 1200 | 505 | | services.TryAdd(new ServiceDescriptor(typeof(TServiceType), typeof(TImplementationType), serviceLifetime)); |
| 1200 | 506 | | } |
| | 507 | |
|
| | 508 | | private static void TryAddEnumerable<TServiceType, TImplementationType>( |
| | 509 | | this IServiceCollection services, |
| | 510 | | ServiceLifetime serviceLifetime) |
| | 511 | | where TImplementationType : TServiceType |
| | 512 | | { |
| 40 | 513 | | services.TryAddEnumerable(new ServiceDescriptor(typeof(TServiceType), typeof(TImplementationType), serviceLifeti |
| 40 | 514 | | } |
| | 515 | |
|
| | 516 | | private static List<Type> GetModuleTypesFromAssemblies(IReadOnlyCollection<Assembly> assemblies) |
| | 517 | | { |
| 3 | 518 | | return assemblies |
| 3 | 519 | | .Distinct() |
| 3 | 520 | | .SelectMany(a => a.GetTypes()) |
| 6 | 521 | | .SelectMany(type => new[] { type }.Union(type.GetNestedTypes())) |
| 6 | 522 | | .Where(type => !type.IsAbstract && typeof(IStrainerModule).IsAssignableFrom(type)) |
| 3 | 523 | | .ToList(); |
| | 524 | | } |
| | 525 | | } |