Beispiel #1
0
        private static IEnumerable <IDependency> ResolveEnumerableDependencies(IEnumerable <IDependency> unresolvedDependencies,
                                                                               IDictionary <IDependency, IInstantiationPoint> availableServices, IDictionary <IDependency, ICollection <IInstantiationPoint> > pointsGroupedByDependency)
        {
            // Resolve all IEnumerable services
            var enumerableDependencies =
                unresolvedDependencies.Where(
                    d => d?.DependencyType != null &&
                    d.DependencyType.IsGenericType &&
                    d.DependencyType.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                .Where(d => availableServices.Keys.Any(k => k.DependencyType == d.DependencyType.GenericTypeArguments[0]))
                .ToArray();

            foreach (var dependency in enumerableDependencies)
            {
                var serviceType = dependency.DependencyType.GenericTypeArguments[0];
                var availableDependenciesOfThatType = availableServices.Keys.Where(k => k.DependencyType == serviceType);

                var enumerablePoint = new EnumerableInstantiationPoint(dependency, availableDependenciesOfThatType);
                availableServices[dependency] = enumerablePoint;
            }

            ResolveFrom(pointsGroupedByDependency, availableServices);
            return(enumerableDependencies);
        }
Beispiel #2
0
        private static IEnumerable<IDependency> ResolveEnumerableDependencies(IEnumerable<IDependency> unresolvedDependencies,
            IDictionary<IDependency, IInstantiationPoint> availableServices, IDictionary<IDependency, ICollection<IInstantiationPoint>> pointsGroupedByDependency)
        {
            // Resolve all IEnumerable services
            var enumerableDependencies =
                unresolvedDependencies.Where(
                    d => d?.DependencyType != null &&
                         d.DependencyType.IsGenericType &&
                         d.DependencyType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
                    .Where(d => availableServices.Keys.Any(k => k.DependencyType == d.DependencyType.GenericTypeArguments[0]))
                    .ToArray();

            foreach (var dependency in enumerableDependencies)
            {
                var serviceType = dependency.DependencyType.GenericTypeArguments[0];
                var availableDependenciesOfThatType = availableServices.Keys.Where(k => k.DependencyType == serviceType);

                var enumerablePoint = new EnumerableInstantiationPoint(dependency, availableDependenciesOfThatType);
                availableServices[dependency] = enumerablePoint;
            }

            ResolveFrom(pointsGroupedByDependency, availableServices);
            return enumerableDependencies;
        }