Esempio n. 1
0
        public IEnumerator <List <object> > GetAllInstancesWithInjectSplit(InjectContext context, List <TypeValuePair> args)
        {
            Assert.IsEmpty(args);
            Assert.IsNotNull(context);

            Assert.That(typeof(TReturn).DerivesFromOrEqual(context.MemberType));

            if (_container.IsValidating && !DiContainer.CanCreateOrInjectDuringValidation(context.MemberType))
            {
                yield return(new List <object>()
                {
                    new ValidationMarker(typeof(TReturn))
                });
            }
            else
            {
                var result = _method(context);

                if (result == null)
                {
                    throw Assert.CreateException(
                              "Method '{0}' returned null when list was expected. Object graph: {1}",
                              _method.ToDebugString(), context.GetObjectGraphString());
                }

                yield return(result.Cast <object>().ToList());
            }
        }
        public IEnumerator <List <object> > GetAllInstancesWithInjectSplit(InjectContext context, List <TypeValuePair> args)
        {
            Assert.IsNotNull(context);

            if (_instances != null)
            {
                yield return(_instances);

                yield break;
            }

#if !ZEN_MULTITHREADING
            // This should only happen with constructor injection
            // Field or property injection should allow circular dependencies
            if (_isCreatingInstance)
            {
                throw Assert.CreateException(
                          "Found circular dependency when creating type '{0}'. Object graph: {1}",
                          _creator.GetInstanceType(context), context.GetObjectGraphString());
            }
#endif

            _isCreatingInstance = true;

            var runner = _creator.GetAllInstancesWithInjectSplit(context, args);

            // First get instance
            bool hasMore = runner.MoveNext();

            _instances = runner.Current;
            Assert.IsNotNull(_instances);
            _isCreatingInstance = false;

            yield return(_instances);

            // Now do injection
            while (hasMore)
            {
                hasMore = runner.MoveNext();
            }
        }
        public DiContainer CreateSubContainer(List <TypeValuePair> args, InjectContext context)
        {
            // We can't really support arguments if we are using the cached value since
            // the arguments might change when called after the first time
            Assert.IsEmpty(args);

            if (_subContainer == null)
            {
                Assert.That(!_isLookingUp,
                            "Found unresolvable circular dependency when looking up sub container!  Object graph: {0}", context.GetObjectGraphString());
                _isLookingUp  = true;
                _subContainer = _subCreator.CreateSubContainer(new List <TypeValuePair>(), context);
                _isLookingUp  = false;
                Assert.IsNotNull(_subContainer);
            }

            return(_subContainer);
        }