/// <summary>
 /// Iterates on the dependencies queue expanding all calculated dependendies inside
 /// this same queue
 /// </summary>
 /// <param name="queue"></param>
 private void ExpandDependencies(DependenciesQueue queue)
 {
     //Process all generated dependencies.
     while (queue.PendingCount != 0)
     {
         var resolutionInfo   = queue.Pop();
         var objectValue      = resolutionInfo.value;
         var dependencyValues = SurrogatesDirectory.GetObjectDependencies(objectValue, _stateManager, _stateManager.surrogateManager, this);
         foreach (var dependencyValue in dependencyValues)
         {
             if (dependencyValue != null)
             {
                 DependencyResolutionInfo resolutionInfoForDependency;
                 if (!queue.TryGetValue(dependencyValue, out resolutionInfoForDependency))
                 {
                     queue.Add(dependencyValue, resolutionInfoForDependency = new DependencyResolutionInfo());
                 }
                 queue.RegisterParentDependency(new DependencyParentInfo()
                 {
                     child = resolutionInfoForDependency, ParentValue = objectValue, ParentSurrogate = resolutionInfo.ResolvedSurrogate
                 });
             }
             else
             {
                 queue.RegisterParentDependency(new DependencyParentInfo()
                 {
                     child = null, ParentValue = objectValue, ParentSurrogate = resolutionInfo.ResolvedSurrogate
                 });
             }
         }
     }
 }
        public void ProcessDependencies()
        {
            //Lets get the current surrogates
            var surrogatesDictionary = _stateManager.surrogateManager.GetSurrogates();

            if (surrogatesDictionary.Count == 0)
            {
                return;
            }
            var queue = new DependenciesQueue();

            //First step: Populate the queue with the surrogates list
            foreach (var surrKeyValuePair in surrogatesDictionary)
            {
                var objectValue = surrKeyValuePair.Key;
                queue.Add(objectValue, new DependencyResolutionInfo()
                {
                    ResolvedSurrogate = surrKeyValuePair.Value, ResolvedValue = surrKeyValuePair.Value
                });
            }
            //Second step: Expand this queue by calculating dependencies
            ExpandDependencies(queue);
            foreach (var resolutionInfo in queue.Values)
            {
                GetResolvedValueEx(resolutionInfo);
            }
            foreach (var pendingParent in queue.PendingParents)
            {
                ProcessPendingParent(pendingParent);
            }
            _stateManager.surrogateManager.AllDependenciesAreProcessed = true;
        }