public SerializableContextual(IContextual contextual, IContextualStore contextualStore) { _cachedContextualStore = contextualStore; if (contextual.GetType().IsSerializable) { _serializable = contextual; } else { _id = contextualStore.PutIfAbsent(contextual); } _cached = contextual; }
public IEnumerable <IComponent> GetComponents(Type type, IQualifier[] qualifiers) { qualifiers = qualifiers.DefaultIfEmpty(DefaultAttribute.Instance).ToArray(); var unwrappedType = UnwrapType(type); var isWrapped = unwrappedType != type; var components = _typeComponents.GetOrAdd(unwrappedType, t => _allComponents.Select(x => x.Resolve(t)).Where(x => x != null).ToArray()); var matched = components.Where(x => x.CanSatisfy(qualifiers)).ToArray(); if (matched.Length > 1) { var onMissings = matched.Where(x => x.IsConditionalOnMissing).ToArray(); var others = matched.Except(onMissings).ToArray(); matched = others.Any() ? others: onMissings.Take(1).ToArray(); } var newComponents = matched.Where(x => !_allComponents.Contains(x)); foreach (var c in newComponents) { _allComponents.Add(c); ContextualStore.PutIfAbsent(c); if (_isDeployed) { Validate(c, new IComponent[0]); } } if (isWrapped) { matched = new IWeldComponent[] { new InstanceComponent(unwrappedType, qualifiers, this, matched) } } ; return(matched); }