Exemplo n.º 1
0
        private IValueProviderContext CreateValueProviderContext([CanBeNull] ValueProviderLink providerLink, IKey key)
        {
            if (providerLink == null)
            {
                return(null);
            }

            var previousLink    = providerLink.Previous?.Invoke();
            var previousContext = previousLink == null ? null : CreateValueProviderContext(previousLink, key);

            return(providerLink.Value.CreateContext(
                       new ValueProviderObjectContext(
                           _compoundValueProvider,
                           (metadata) =>
            {
                if (previousLink == null)
                {
                    throw new MissingValueProviderException(
                        $"Tried to call previous provider on '{key}' but no previous provider was registered. " +
                        "Are you missing a value provider registration?");
                }

                return
                CreateInstances(previousLink.Key, previousLink.Value, previousContext, metadata == null ? null : new[] { metadata }, 1).Single();
            },
                           key.Type,
                           new ValueProviderObjectContext.AdvancedContext(
                               key,
                               _memberSorter,
                               _metadataResolver,
                               _parameterConversionService,
                               _compoundValueProvider,
                               _fastReflectionUtility),
                           key.Member)));
        }
 internal void AddValueProvider(IKey key, IValueProvider valueProvider)
 {
     if (!_valueProviders.ContainsKey(key))
     {
         _valueProviders[key] = new ValueProviderLink(valueProvider, key, () => key.PreviousKey == null ? null : GetLink(key.PreviousKey));
     }
     else
     {
         var previousKey = _valueProviders[key];
         _valueProviders[key] = new ValueProviderLink(valueProvider, key, () => previousKey);
     }
 }
        internal ValueProviderLink GetLink(IKey key)
        {
            ValueProviderLink link = null;
            var concreteType       = key.Type;

            while ((link?.Value == null || !link.Value.CanHandle(concreteType)) && key != null)
            {
                link = GetOrDefault(key);
                key  = key.PreviousKey;
            }

            return(link);
        }