예제 #1
0
        /// <summary>
        /// Locate specific type using extra data or key
        /// </summary>
        /// <param name="type">type to locate</param>
        /// <param name="extraData">extra data to be used during construction</param>
        /// <param name="consider"></param>
        /// <param name="withKey">key to use for locating type</param>
        /// <param name="isDynamic"></param>
        /// <returns>located instance</returns>
        // ReSharper disable once MethodOverloadWithOptionalParameter
        public override object Locate(Type type, object extraData = null, ActivationStrategyFilter consider = null, object withKey = null, bool isDynamic = false)
        {
            if (isDynamic || withKey != null || consider != null)
            {
                return(LocateFromParent(type, extraData, consider, withKey, false, isDynamic));
            }

            return(DelegateCache.ExecuteActivationStrategyDelegateWithContext(type, this, false, extraData != null ? CreateContext(extraData) : null));
        }
예제 #2
0
        /// <summary>
        /// Locate specific type using extra data or key
        /// </summary>
        /// <param name="type">type to locate</param>
        /// <param name="extraData">extra data to be used during construction</param>
        /// <param name="consider">filter out exports you don't want to consider</param>
        /// <param name="withKey">key to use for locating type</param>
        /// <param name="isDynamic">skip cache and look through exports</param>
        /// <returns>located instance</returns>
        // ReSharper disable once MethodOverloadWithOptionalParameter
        public override object Locate(Type type, object extraData = null, ActivationStrategyFilter consider = null, object withKey = null, bool isDynamic = false)
        {
            IInjectionContext context = extraData == null ?
                                        null : CreateInjectionContextFromExtraData(type, extraData);

            if (withKey == null && consider == null && !isDynamic)
            {
                return(DelegateCache.ExecuteActivationStrategyDelegateWithContext(type, this, false, context));
            }

            return(InternalLocate(this, this, type, consider, withKey, context, false, isDynamic));
        }
예제 #3
0
        /// <summary>
        /// try to locate a specific type
        /// </summary>
        /// <param name="type">type to locate</param>
        /// <param name="value">located value</param>
        /// <param name="extraData">extra data to be used during locate</param>
        /// <param name="consider">filter to use during location</param>
        /// <param name="withKey">key to use during locate</param>
        /// <param name="isDynamic">is the request dynamic</param>
        /// <returns>true if export could be located</returns>
        public override bool TryLocate(Type type, out object value, object extraData = null, ActivationStrategyFilter consider = null, object withKey = null, bool isDynamic = false)
        {
            if (!isDynamic && withKey == null && consider == null)
            {
                var hashCode = type.GetHashCode();

                value = DelegateCache.ExecuteActivationStrategyDelegateWithContext(type, this, true, extraData == null ? null : CreateContext(extraData));

                return(value != null);
            }

            value = LocateFromParent(type, extraData, consider, withKey, true, isDynamic);

            return(value != null);
        }