示例#1
0
        /// <summary>
        /// Called during the chain of responsibility for a build operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(IBuilderContext context)
        {
            DynamicBuildPlanGenerationContext ilContext = (DynamicBuildPlanGenerationContext)(context.Existing);

            IPropertySelectorPolicy selector = context.Policies.Get <IPropertySelectorPolicy>(context.BuildKey);

            foreach (SelectedProperty property in selector.SelectProperties(context))
            {
                // Set the current operation to resolving
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.EmitLoadContext();
                ilContext.IL.EmitCall(OpCodes.Call, setCurrentOperationToResolvingPropertyValue, null);

                // Resolve the property value
                ilContext.EmitLoadExisting();
                ilContext.EmitResolveDependency(property.Property.PropertyType, property.Key);

                // Set the current operation to setting
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.EmitLoadContext();
                ilContext.IL.EmitCall(OpCodes.Call, setCurrentOperationToSettingProperty, null);

                // Call the property setter
                ilContext.IL.EmitCall(OpCodes.Callvirt, property.Property.GetSetMethod(), null);
            }

            // Clear the current operation
            ilContext.EmitClearCurrentOperation();
        }
 public void SetDefault(Type policyInterface, IBuilderPolicy policy)
 {
     if (policyInterface == typeof(IPropertySelectorPolicy))
     {
         this.PropertySelectorPolicy = (IPropertySelectorPolicy)policy;
     }
     else
     {
         throw new NotImplementedException();
     }
 }
示例#3
0
        private static SpecifiedPropertiesSelectorPolicy GetSelectorPolicy(IPolicyList policies, Type typeToInject, string name)
        {
            NamedTypeBuildKey       key      = new NamedTypeBuildKey(typeToInject, name);
            IPropertySelectorPolicy selector =
                policies.GetNoDefault <IPropertySelectorPolicy>(key, false);

            if (selector == null || !(selector is SpecifiedPropertiesSelectorPolicy))
            {
                selector = new SpecifiedPropertiesSelectorPolicy();
                policies.Set <IPropertySelectorPolicy>(selector, key);
            }
            return((SpecifiedPropertiesSelectorPolicy)selector);
        }
示例#4
0
        private static SpecifiedPropertiesSelectorPolicy GetSelectorPolicy(IPolicyList policies, Type typeToInject, string name)
        {
            NamedTypeBuildKey       key      = new NamedTypeBuildKey(typeToInject, name);
            IPropertySelectorPolicy selector =
                (IPropertySelectorPolicy)policies.Get(typeToInject, name, typeof(IPropertySelectorPolicy), out _);

            if (!(selector is SpecifiedPropertiesSelectorPolicy))
            {
                selector = new SpecifiedPropertiesSelectorPolicy();
                policies.Set(key.Type, key.Name, typeof(IPropertySelectorPolicy), selector);
            }
            return((SpecifiedPropertiesSelectorPolicy)selector);
        }
示例#5
0
        /// <summary>
        /// Called during the chain of responsibility for a build operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(IBuilderContext context)
        {
            DynamicBuildPlanGenerationContext ilContext = (DynamicBuildPlanGenerationContext)(context.Existing);

            IPropertySelectorPolicy selector = context.Policies.Get <IPropertySelectorPolicy>(context.BuildKey);

            foreach (SelectedProperty property in selector.SelectProperties(context))
            {
                ilContext.EmitLoadExisting();
                ilContext.EmitResolveDependency(property.Property.PropertyType, property.Key);
                ilContext.IL.EmitCall(OpCodes.Callvirt, property.Property.GetSetMethod(), null);
            }
        }
 private static void ResolveProperties(IBuilderContext context, IPropertySelectorPolicy propertySelector,
                                       IPolicyList resolverPolicyDestination, Dictionary <string, StepScopeDependency> properties)
 {
     foreach (var property in propertySelector.SelectProperties(context, resolverPolicyDestination))
     {
         var namedTypeResolver = property.Resolver as NamedTypeDependencyResolverPolicy;
         if (namedTypeResolver != null)
         {
             var type = namedTypeResolver.Type;
             var name = namedTypeResolver.Name;
             if (StepScopeSynchronization.IsStepScope(type, name))
             {
                 properties[property.Property.Name] = new StepScopeDependency(type, name);
             }
         }
     }
 }
示例#7
0
        private static SpecifiedPropertiesSelectorPolicy GetSelectorPolicy(IPolicyList policies, Type typeToInject, string name)
        {
            NamedTypeBuildKey       key      = new NamedTypeBuildKey(typeToInject, name);
            IPropertySelectorPolicy selector =
                policies.GetNoDefault <IPropertySelectorPolicy>(key, false);

            if (selector == null)
            {
                FullAutowirePropertySelectorPolicy defaultSelector =
                    policies.Get <IPropertySelectorPolicy>(key, false) as FullAutowirePropertySelectorPolicy;
                if (defaultSelector != null)
                {
                    selector = defaultSelector.Clone();
                    policies.Set(selector, key);
                }
                else
                {
                    throw new InvalidOperationException("Cannot use AutiviewEnabledInjectionProperty without FullAutowireContainerExtension. Please register FullAutowireContainerExtension extension in the container.");
                }
            }
            return(((FullAutowirePropertySelectorPolicy)selector).SpecifiedPropertiesPolicy);
        }
        /// <summary>
        /// Called during the chain of responsibility for a build operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(IBuilderContext context)
        {
            DynamicBuildPlanGenerationContext ilContext = (DynamicBuildPlanGenerationContext)(context.Existing);

            IPropertySelectorPolicy selector            = context.Policies.Get <IPropertySelectorPolicy>(context.BuildKey);
            LocalBuilder            resolving           = ilContext.IL.DeclareLocal(typeof(bool));
            LocalBuilder            currentPropertyName = ilContext.IL.DeclareLocal(typeof(string));

            ilContext.IL.BeginExceptionBlock();

            foreach (SelectedProperty property in selector.SelectProperties(context))
            {
                // Resolve the property value
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.IL.Emit(OpCodes.Stloc, currentPropertyName);
                ilContext.IL.Emit(OpCodes.Ldc_I4_1);
                ilContext.IL.Emit(OpCodes.Stloc, resolving);
                ilContext.EmitLoadExisting();
                ilContext.EmitResolveDependency(property.Property.PropertyType, property.Key);

                // Call the property setter
                ilContext.IL.Emit(OpCodes.Ldc_I4_0);
                ilContext.IL.Emit(OpCodes.Stloc, resolving);
                ilContext.IL.EmitCall(OpCodes.Callvirt, property.Property.GetSetMethod(), null);
            }

            // Catch any exceptions in the setting of the properties
            ilContext.IL.BeginCatchBlock(typeof(Exception));
            Label failedWhileResolving = ilContext.IL.DefineLabel();

            ilContext.IL.Emit(OpCodes.Ldloc, resolving);
            ilContext.IL.Emit(OpCodes.Brtrue, failedWhileResolving);
            ilContext.IL.Emit(OpCodes.Rethrow);

            ilContext.IL.MarkLabel(failedWhileResolving);
            ilContext.IL.Emit(OpCodes.Ldloc, currentPropertyName);
            ilContext.IL.EmitCall(OpCodes.Call, throwOnFailedPropertyValueResolution, null);
            ilContext.IL.EndExceptionBlock();
        }
示例#9
0
        /// <summary>
        /// Called during the chain of responsibility for a build operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(IBuilderContext context)
        {
            Guard.ArgumentNotNull(context, "context");
            DynamicBuildPlanGenerationContext ilContext = (DynamicBuildPlanGenerationContext)(context.Existing);

            IPolicyList             resolverPolicyDestination;
            IPropertySelectorPolicy selector = context.Policies.Get <IPropertySelectorPolicy>(context.BuildKey, out resolverPolicyDestination);

            bool shouldClearOperation = false;

            foreach (SelectedProperty property in selector.SelectProperties(context, resolverPolicyDestination))
            {
                shouldClearOperation = true;
                // Set the current operation to resolving
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.EmitLoadContext();
                ilContext.IL.EmitCall(OpCodes.Call, setCurrentOperationToResolvingPropertyValue, null);

                // Resolve the property value
                ilContext.EmitLoadExisting();
                ilContext.EmitResolveDependency(property.Property.PropertyType, property.Key);

                // Set the current operation to setting
                ilContext.IL.Emit(OpCodes.Ldstr, property.Property.Name);
                ilContext.EmitLoadContext();
                ilContext.IL.EmitCall(OpCodes.Call, setCurrentOperationToSettingProperty, null);

                // Call the property setter
                ilContext.IL.EmitCall(OpCodes.Callvirt, GetValidatedPropertySetter(property.Property), null);
            }

            // Clear the current operation
            if (shouldClearOperation)
            {
                ilContext.EmitClearCurrentOperation();
            }
        }
示例#10
0
 private static void ResolveProperties(IBuilderContext context, IPropertySelectorPolicy propertySelector,
     IPolicyList resolverPolicyDestination, Dictionary<string, StepScopeDependency> properties)
 {
     foreach (var property in propertySelector.SelectProperties(context, resolverPolicyDestination))
     {
         var namedTypeResolver = property.Resolver as NamedTypeDependencyResolverPolicy;
         if (namedTypeResolver != null)
         {
             var type = namedTypeResolver.Type;
             var name = namedTypeResolver.Name;
             if (StepScopeSynchronization.IsStepScope(type, name))
             {
                 properties[property.Property.Name] = new StepScopeDependency(type, name);
             }
         }
     }
 }
示例#11
0
 public void SetPropertySelectorPolicy(IPropertySelectorPolicy policy)
 {
     this.propertySelectorPolicy = policy;
 }