Exemplo n.º 1
0
        /// <summary>
        /// Get value from scope
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="scope"></param>
        /// <param name="creationDelegate"></param>
        /// <param name="uniqueId"></param>
        /// <param name="scopeName"></param>
        /// <param name="context"></param>
        /// <param name="staticContext"></param>
        /// <param name="shareContext"></param>
        /// <returns></returns>
        public static T GetValueFromScope <T>(IExportLocatorScope scope, ActivationStrategyDelegate creationDelegate,
                                              string uniqueId,
                                              string scopeName,
                                              bool shareContext,
                                              IInjectionContext context,
                                              StaticInjectionContext staticContext)
        {
            while (scope != null)
            {
                if (scope.ScopeName == scopeName)
                {
                    break;
                }

                scope = scope.Parent;
            }

            if (scope == null)
            {
                throw new NamedScopeLocateException(scopeName, staticContext);
            }

            var value = scope.GetExtraData(uniqueId);

            if (value != null)
            {
                return((T)value);
            }

            lock (scope.GetLockObject(uniqueId))
            {
                value = scope.GetExtraData(uniqueId);

                if (value == null)
                {
                    value = creationDelegate(scope, scope, shareContext ? context : null);

                    scope.SetExtraData(uniqueId, value);
                }
            }

            return((T)value);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get value from scope using lock
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="scope"></param>
        /// <param name="creationDelegate"></param>
        /// <param name="uniqueId"></param>
        /// <param name="shareContext"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static T GetValueFromScopeThreadSafe <T>(IExportLocatorScope scope, ActivationStrategyDelegate creationDelegate, string uniqueId, bool shareContext, IInjectionContext context)
        {
            var value = scope.GetExtraData(uniqueId);

            if (value != null)
            {
                return((T)value);
            }

            lock (scope.GetLockObject(uniqueId))
            {
                value = scope.GetExtraData(uniqueId);

                if (value == null)
                {
                    value = creationDelegate(scope, scope, shareContext ? context : null);

                    scope.SetExtraData(uniqueId, value);
                }
            }

            return((T)value);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get value from scope with no lock
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="scope"></param>
        /// <param name="creationDelegate"></param>
        /// <param name="uniqueId"></param>
        /// <returns></returns>
        public static T GetValueFromScope <T>(IExportLocatorScope scope, ActivationStrategyDelegate creationDelegate,
                                              string uniqueId)
        {
            var value = scope.GetExtraData(uniqueId);

            if (value != null)
            {
                return((T)value);
            }

            value = creationDelegate(scope, scope, null);

            scope.SetExtraData(uniqueId, value);

            return((T)value);
        }
 /// <summary>
 /// Get value from scope with no lock
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="scope"></param>
 /// <param name="creationDelegate"></param>
 /// <param name="uniqueId"></param>
 /// <returns></returns>
 public static T GetValueFromScope <T>(IExportLocatorScope scope, ActivationStrategyDelegate creationDelegate,
                                       string uniqueId)
 {
     return((T)(scope.GetExtraData(uniqueId) ??
                scope.SetExtraData(uniqueId, creationDelegate(scope, scope, null), false)));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Get value from scope with no lock
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="scope"></param>
 /// <param name="creationDelegate"></param>
 /// <param name="uniqueId"></param>
 /// <param name="shareContext"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public static T GetValueFromScope <T>(IExportLocatorScope scope, ActivationStrategyDelegate creationDelegate,
                                       string uniqueId, bool shareContext, IInjectionContext context)
 {
     return((T)(scope.GetExtraData(uniqueId) ??
                scope.SetExtraData(uniqueId, creationDelegate(scope, scope, shareContext ? context : null), false)));
 }