/// <summary> /// Imports the <see cref="IParserContext"/>-Mappings for the <see cref="Type"/> of the supplied sources. /// </summary> /// <param name="parserContext">The <see cref="IParserContext"/> to fill with mappings.</param> /// <param name="sourceObjects">A list of source objects which <see cref="Type"/>`s are used to construct the <see cref="LambdaExpression"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="parserContext"/>' and '<paramref name="sourceObjects"/>' cannot be null. </exception> /// <exception cref="InvalidOperationException">No element satisfies the condition in <paramref name="predicate" />.-or-More than one element satisfies the condition in <paramref name="predicate" />.-or-The source sequence is empty.</exception> /// <exception cref="ArgumentException">The supplied property path does not contain any parts.</exception> /// <exception cref="ConstructedPropertyPathDoesNotContainAnyPartsException">Thee supplied property path '<paramref name="propertyPath"/>' does not contain any constructible parts for Type '<paramref name="sourceType"/>'. </exception> public static void ImportConfiguration([NotNull] this IParserContext parserContext, [NotNull] params Object[] sourceObjects) { if (parserContext == null) { throw new ArgumentNullException(nameof(parserContext)); } if (sourceObjects == null) { throw new ArgumentNullException(nameof(sourceObjects)); } var configuration = QueryfyConfigurationSection.GetXmlConfiguration(); if (configuration == null) { throw new ConfigurationErrorsException(); } if (configuration.ParserConfiguration != null && configuration.ParserConfiguration.TypeMappings != null) { foreach (var source in sourceObjects) { var closuredSource = source; var parserTypeMappings = configuration.ParserConfiguration.TypeMappings.Single(m => m.SourceType == closuredSource.GetType()); foreach (var propertyMapping in parserTypeMappings.PropertyMappings) { var lambda = LambdaExpressionDeserializer.Deserialize(closuredSource.GetType(), propertyMapping.PropertyPath); var propertyType = lambda.GetPropertyInfo(); var valueProcessor = parserContext.ValueProcessorFactory.GetUrlValueProcessor(propertyType.PropertyType, propertyMapping.ValueProcessorType); parserContext.AddPropertyMapping(closuredSource, lambda, propertyMapping.ParameterName, valueProcessor); } } } }
/// <summary> /// Loads the module into the kernel. /// </summary> public override void Load() { this.Bind <IPropertyMetadataFactory>().To <PropertyMetadataFactory>().InSingletonScope(); this.Bind <IQueryfyConfiguration>().ToConstant(QueryfyConfigurationSection.GetXmlConfiguration()).InSingletonScope(); this.Bind <IPropertyReflectorSelector>().To <PropertyReflectorSelector>().InSingletonScope(); this.Bind <IPropertyReflector>().To <ExpandoObjectPropertyReflector>().InSingletonScope(); this.Bind <IPropertyReflector>().To <DynamicObjectPropertyReflector>().InSingletonScope(); this.Bind <IPropertyReflector>().To <PropertyReflector>().InSingletonScope(); this.Bind <IQueryficationBuilder>().To <QueryficationBuilder>().InSingletonScope(); this.Bind <IQueryfyDotNet>().To <QueryfyDotNet>().InSingletonScope(); this.Bind <IInstanceFactory>().To <InstanceFactory>().InSingletonScope(); this.Bind <ITypeValueProcessorRegistry>().ToConstant(TypeValueProcessorRegistry.Global); this.Bind <IContextFactory>().To <ContextFactory>().InSingletonScope(); this.Bind <IQueryficationEngine>().To <QueryficationEngine>().InSingletonScope(); this.Bind <IValueProcessorFactory>().To <ValueProcessorFactory>().InSingletonScope(); this.Bind <IQueryficationContext>().To <QueryficationContext>(); this.Bind <IParserContext>().To <ParserContext>(); this.Bind <ILambdaExpressionInitializer>().To <LambdaExpressionInitializer>().InSingletonScope(); this.Kernel.Components.Add <IMissingBindingResolver, SelfBindingResolver>(); this.Kernel.Components.Add <IMissingBindingResolver, ValueTypeBindingResolver>(); }