Esempio n. 1
0
        /// <summary>
        /// Resolve dependencies on all implementations of a contract.
        /// </summary>
        /// <param name="site">A tag describing the dependency site.</param>
        /// <param name="contract">The contract required by the site.</param>
        /// <param name="isPrerequisite">True if the dependency must be satisifed before corresponding exports can be retrieved; otherwise, false.</param>
        /// <returns>Dependencies for all implementations of the contact.</returns>
        public IEnumerable <CompositionDependency> ResolveDependencies(object site, CompositionContract contract, bool isPrerequisite)
        {
            var all    = GetPromises(contract).ToArray();
            var result = new CompositionDependency[all.Length];

            for (var i = 0; i < all.Length; ++i)
            {
                result[i] = CompositionDependency.Satisfied(contract, all[i], isPrerequisite, site);
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Resolve an optional dependency on exactly one implemenation of a contract.
        /// </summary>
        /// <param name="site">A tag describing the dependency site.</param>
        /// <param name="contract">The contract required by the site.</param>
        /// <param name="isPrerequisite">True if the dependency must be satisifed before corresponding exports can be retrieved; otherwise, false.</param>
        /// <param name="dependency">The dependency, or null.</param>
        /// <returns>True if the dependency could be resolved; otherwise, false.</returns>
        public bool TryResolveOptionalDependency(object site, CompositionContract contract, bool isPrerequisite, out CompositionDependency dependency)
        {
            var all = GetPromises(contract).ToArray();

            if (all.Length == 0)
            {
                dependency = null;
                return(false);
            }

            if (all.Length != 1)
            {
                dependency = CompositionDependency.Oversupplied(contract, all, site);
                return(true);
            }

            dependency = CompositionDependency.Satisfied(contract, all[0], isPrerequisite, site);
            return(true);
        }