示例#1
0
        internal object Create(ServiceName name, bool isEnumerable, object arguments)
        {
            Func <object> compiledFactory;
            var           hasPendingResolutionContext = ResolutionContext.HasPendingResolutionContext;

            if (arguments == null && factoryCache.TryGetValue(name, out compiledFactory) && !hasPendingResolutionContext)
            {
                return(compiledFactory());
            }
            var activation                = ResolutionContext.Push(this);
            ContainerService result       = null;
            List <string>    oldContracts = null;

            try
            {
                if (hasPendingResolutionContext)
                {
                    oldContracts = activation.activated.Contracts.Replace(name.Contracts);
                    name         = new ServiceName(name.Type);
                }
                result = ResolveCore(name, true, ObjectAccessor.Get(arguments), activation.activated);
            }
            finally
            {
                if (oldContracts != null)
                {
                    activation.activated.Contracts.Restore(oldContracts);
                }
                PopResolutionContext(activation, result, isEnumerable);
            }
            if (!hasPendingResolutionContext)
            {
                result.EnsureInitialized(containerContext, result);
            }
            result.CheckStatusIsGood(containerContext);
            if (isEnumerable)
            {
                return(result.GetAllValues());
            }
            result.CheckSingleValue(containerContext);
            return(result.Instances[0].Instance);
        }