| | 1 | | using Fluorite.Strainer.Exceptions; |
| | 2 | | using Fluorite.Strainer.Services.Metadata; |
| | 3 | | using Fluorite.Strainer.Services.Modules; |
| | 4 | |
|
| | 5 | | namespace Fluorite.Strainer.Services.Configuration; |
| | 6 | |
|
| | 7 | | public class StrainerModuleBuilderFactory : IStrainerModuleBuilderFactory |
| | 8 | | { |
| | 9 | | private readonly IPropertyInfoProvider _propertyInfoProvider; |
| | 10 | | private readonly IStrainerOptionsProvider _strainerOptionsProvider; |
| | 11 | |
|
| 12 | 12 | | public StrainerModuleBuilderFactory( |
| 12 | 13 | | IPropertyInfoProvider propertyInfoProvider, |
| 12 | 14 | | IStrainerOptionsProvider strainerOptionsProvider) |
| | 15 | | { |
| 12 | 16 | | _propertyInfoProvider = Guard.Against.Null(propertyInfoProvider); |
| 12 | 17 | | _strainerOptionsProvider = Guard.Against.Null(strainerOptionsProvider); |
| 12 | 18 | | } |
| | 19 | |
|
| | 20 | | public object Create(Type moduleTypeParameter, IStrainerModule strainerModule) |
| | 21 | | { |
| 3 | 22 | | Guard.Against.Null(moduleTypeParameter); |
| 3 | 23 | | Guard.Against.Null(strainerModule); |
| | 24 | |
|
| 3 | 25 | | var options = _strainerOptionsProvider.GetStrainerOptions(); |
| 3 | 26 | | var builderType = typeof(StrainerModuleBuilder<>).MakeGenericType(moduleTypeParameter); |
| | 27 | |
|
| | 28 | | try |
| | 29 | | { |
| 3 | 30 | | return Activator.CreateInstance(builderType, _propertyInfoProvider, strainerModule, options); |
| | 31 | | } |
| 1 | 32 | | catch (Exception ex) |
| | 33 | | { |
| 1 | 34 | | throw new StrainerException($"Unable to create a module builder for module of type {strainerModule.GetType() |
| | 35 | | } |
| 2 | 36 | | } |
| | 37 | | } |