コード例 #1
0
        /// <summary>
        /// Add policies to the <paramref name="policies"/> to configure the
        /// container to call this constructor with the appropriate parameter values.
        /// </summary>
        /// <param name="serviceType">Type of interface registered, ignored in this implementation.</param>
        /// <param name="implementationType">Type to register.</param>
        /// <param name="name">Name used to resolve the type object.</param>
        /// <param name="policies">Policy list to add policies to.</param>
        public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
        {
            MethodInfo methodInfo = this.FindMethod(implementationType);

            this.ValidateMethodCanBeInjected(methodInfo, implementationType);

            SpecifiedMethodsSelectorPolicy selector =
                GetSelectorPolicy(policies, implementationType, name);

            selector.AddMethodAndParameters(methodInfo, this.methodParameters);
        }
コード例 #2
0
        /// <summary>
        /// Add policies to the <paramref name="policies"/> to configure the
        /// container to call this constructor with the appropriate parameter values.
        /// </summary>
        /// <param name="typeToCreate">Type to register.</param>
        /// <param name="name">Name used to resolve the type object.</param>
        /// <param name="policies">Policy list to add policies to.</param>
        public override void AddPolicies(Type typeToCreate, string name, IPolicyList policies)
        {
            MethodInfo methodInfo = FindMethod(typeToCreate);

            ValidateMethodCanBeInjected(methodInfo, typeToCreate);

            SpecifiedMethodsSelectorPolicy selector =
                GetSelectorPolicy(policies, typeToCreate, name);

            selector.AddMethodAndParameters(methodInfo, methodParameters);
        }
コード例 #3
0
        private static SpecifiedMethodsSelectorPolicy GetSelectorPolicy(IPolicyList policies, Type typeToCreate, string name)
        {
            var selector = policies.Get(typeToCreate, name, typeof(IMethodSelectorPolicy), out _);

            if (!(selector is SpecifiedMethodsSelectorPolicy))
            {
                selector = new SpecifiedMethodsSelectorPolicy();
                policies.Set(typeToCreate, name, typeof(IMethodSelectorPolicy), selector);
            }
            return((SpecifiedMethodsSelectorPolicy)selector);
        }
コード例 #4
0
        private static SpecifiedMethodsSelectorPolicy GetSelectorPolicy(IPolicyList policies, Type typeToCreate, string name)
        {
            var key      = new NamedTypeBuildKey(typeToCreate, name);
            var selector = policies.GetNoDefault <IMethodSelectorPolicy>(key, false);

            if (selector == null || !(selector is SpecifiedMethodsSelectorPolicy))
            {
                selector = new SpecifiedMethodsSelectorPolicy();
                policies.Set <IMethodSelectorPolicy>(selector, key);
            }
            return((SpecifiedMethodsSelectorPolicy)selector);
        }
コード例 #5
0
        /// <summary>
        /// Add policies to the <paramref name="policies"/> to configure the
        /// container to call this constructor with the appropriate parameter values.
        /// </summary>
        /// <param name="typeToCreate">Type to register.</param>
        /// <param name="name">Name used to resolve the type object.</param>
        /// <param name="policies">Policy list to add policies to.</param>
        public override void AddPolicies(Type typeToCreate, string name, IPolicyList policies)
        {
            MethodInfo methodInfo = typeToCreate.GetMethod(methodName,
                                                           Sequence.ToArray(
                                                               Sequence.Map <InjectionParameterValue, Type>(methodParameters,
                                                                                                            delegate(InjectionParameterValue value)
            {
                return(value.ParameterType);
            })));

            ValidateMethodCanBeInjected(methodInfo, typeToCreate);

            SpecifiedMethodsSelectorPolicy selector =
                GetSelectorPolicy(policies, typeToCreate, name);

            selector.AddMethodAndParameters(methodInfo, methodParameters);
        }