Ejemplo n.º 1
0
        private bool TryResolve(Type resolvingType, out object dependency, int hierarchyDepthCount)
        {
            if (IsDestroyed)
            {
                throw new BehaviourInjectException(String.Format("Can not resolve {0}. Context {1} is destroyed.", resolvingType, _name));
            }

            if (hierarchyDepthCount > MAX_HIERARCHY_DEPTH)
            {
                throw new BehaviourInjectException(String.Format("You have reached maximum hierarchy depth ({0}). Probably recursive dependencies are occured in {1}", MAX_HIERARCHY_DEPTH, resolvingType.FullName));
            }

            hierarchyDepthCount++;

            object parentDependency;

            if (_dependencies.ContainsKey(resolvingType))
            {
                dependency = _dependencies[resolvingType].Resolve(this, hierarchyDepthCount);
            }
            else if (_parentContext.TryResolve(resolvingType, out parentDependency))
            {
                dependency = parentDependency;
            }
            else
            {
                dependency = null;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool TryResolve(Type resolvingType, out object dependency, int hierarchyDepthCount)
        {
            //UnityEngine.Debug.Log("resolving " + resolvingType.Name + " lvl " + hierarchyDepthCount);
            if (hierarchyDepthCount > MAX_HIERARCHY_DEPTH)
            {
                throw new BehaviourInjectException(String.Format("You have reached maximum hierarchy depth ({0}). Probably recursive dependencies are occured in {1}", MAX_HIERARCHY_DEPTH, resolvingType.FullName));
            }
            else
            {
                hierarchyDepthCount++;
            }

            object parentDependency;

            if (_dependencies.ContainsKey(resolvingType))
            {
                dependency = _dependencies[resolvingType];
            }
            else if (_factories.ContainsKey(resolvingType))
            {
                dependency = _factories[resolvingType].Create();
            }
            else if (_autoCompositionTypes.Contains(resolvingType))
            {
                dependency = AutocomposeDependency(resolvingType, hierarchyDepthCount);
            }
            else if (_parentContext.TryResolve(resolvingType, out parentDependency))
            {
                dependency = parentDependency;
            }
            else
            {
                dependency = null;
                return(false);
            }

            return(true);
        }