private CompositionDependency(CompositionContract contract, object site) { _contract = contract; _site = site; }
/// <summary> /// Get all definitions for a specified <see cref="CompositionContract"/>. /// </summary> /// <param name="exportKey">The export key the definitions must supply.</param> /// <returns>The available promises for that export key.</returns> protected abstract IEnumerable <ExportDescriptorPromise> GetPromises(CompositionContract exportKey);
/// <summary> /// Promise export descriptors for the specified export key. /// </summary> /// <param name="contract">The export key required by another component.</param> /// <param name="descriptorAccessor">Accesses the other export descriptors present in the composition.</param> /// <returns>Promises for new export descriptors.</returns> /// <remarks> /// A provider will only be queried once for each unique export key. /// The descriptor accessor can only be queried immediately if the descriptor being promised is an adapter, such as /// <see cref="Lazy{T}"/>; otherwise, dependencies should only be queried within execution of the function provided /// to the <see cref="ExportDescriptorPromise"/>. The actual descriptors provided should not close over or reference any /// aspect of the dependency/promise structure, as this should be able to be GC'ed. /// </remarks> public abstract IEnumerable <ExportDescriptorPromise> GetExportDescriptors( CompositionContract contract, DependencyAccessor descriptorAccessor);
/// <summary> /// Check the contract for a constraint with a particular name and value, and, if it exists, /// retrieve both the value and the remainder of the contract with the constraint /// removed. /// </summary> /// <typeparam name="T">The type of the constraint value.</typeparam> /// <param name="constraintName">The name of the constraint.</param> /// <param name="constraintValue">The value if it is present and of the correct type, otherwise null.</param> /// <param name="remainingContract">The contract with the constraint removed if present, otherwise null.</param> /// <returns>True if the constraint is present and of the correct type, otherwise false.</returns> public bool TryUnwrapMetadataConstraint <T>(string constraintName, out T constraintValue, out CompositionContract remainingContract) { if (constraintName is null) { throw new ArgumentNullException(nameof(constraintName)); } constraintValue = default(T); remainingContract = null; if (_metadataConstraints == null) { return(false); } if (!_metadataConstraints.TryGetValue(constraintName, out object value)) { return(false); } if (!(value is T)) { return(false); } constraintValue = (T)value; if (_metadataConstraints.Count == 1) { remainingContract = new CompositionContract(_contractType, _contractName); } else { var remainingConstraints = new Dictionary <string, object>(_metadataConstraints); remainingConstraints.Remove(constraintName); remainingContract = new CompositionContract(_contractType, _contractName, remainingConstraints); } return(true); }
private CompositionDependency(CompositionContract contract, IEnumerable <ExportDescriptorPromise> targets, object site) { _oversuppliedTargets = targets.ToArray(); _site = site; _contract = contract; }