| | 1 | | using Fluorite.Strainer.Services.Modules; |
| | 2 | |
|
| | 3 | | namespace Fluorite.Strainer.Services.Configuration; |
| | 4 | |
|
| | 5 | | public class ModuleLoadingStrategySelector : IModuleLoadingStrategySelector |
| | 6 | | { |
| | 7 | | private readonly IGenericModuleLoadingStrategy _genericModuleLoadingStrategy; |
| | 8 | | private readonly IPlainModuleLoadingStrategy _plainModuleLoadingStrategy; |
| | 9 | |
|
| 10 | 10 | | public ModuleLoadingStrategySelector( |
| 10 | 11 | | IGenericModuleLoadingStrategy genericModuleLoadingStrategy, |
| 10 | 12 | | IPlainModuleLoadingStrategy plainModuleLoadingStrategy) |
| | 13 | | { |
| 10 | 14 | | _genericModuleLoadingStrategy = Guard.Against.Null(genericModuleLoadingStrategy); |
| 10 | 15 | | _plainModuleLoadingStrategy = Guard.Against.Null(plainModuleLoadingStrategy); |
| 10 | 16 | | } |
| | 17 | |
|
| | 18 | | public IModuleLoadingStrategy Select(IStrainerModule strainerModule) |
| | 19 | | { |
| 6 | 20 | | Guard.Against.Null(strainerModule); |
| | 21 | |
|
| 6 | 22 | | var isGeneric = strainerModule |
| 6 | 23 | | .GetType() |
| 6 | 24 | | .GetInterfaces() |
| 12 | 25 | | .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IStrainerModule<>)); |
| | 26 | |
|
| 6 | 27 | | return isGeneric |
| 6 | 28 | | ? _genericModuleLoadingStrategy |
| 6 | 29 | | : _plainModuleLoadingStrategy; |
| | 30 | | } |
| | 31 | | } |