private static Func <IResolutionScope, object> GetFactoryDelegateForRegistration(ExpressionBuilder expressionBuilder,
                                                                                         ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type requestedType)
        {
            if (!IsRegistrationOutputCacheable(serviceRegistration, resolutionContext))
            {
                return(GetNewFactoryDelegate(expressionBuilder, serviceRegistration, resolutionContext.BeginSubGraph(), requestedType));
            }

            var factory = resolutionContext.GetCachedFactory(serviceRegistration.RegistrationId);

            if (factory != null)
            {
                return(factory);
            }

            factory = GetNewFactoryDelegate(expressionBuilder, serviceRegistration, resolutionContext.BeginSubGraph(), requestedType);
            resolutionContext.CacheFactory(serviceRegistration.RegistrationId, factory);
            return(factory);
        }