Beispiel #1
0
        private static void ResolveGenericDependencies(IEnumerable <IDependency> unresolvedDependencies,
                                                       IEnumerable <IDependency> enumerableDependencies, IDictionary <IDependency, IInstantiationPoint> availableServices,
                                                       IDictionary <IDependency, ICollection <IInstantiationPoint> > pointsGroupedByDependency)
        {
            var genericDependencies = unresolvedDependencies.Where(
                d => d?.DependencyType != null &&
                d.DependencyType.IsGenericType && !d.DependencyType.IsGenericTypeDefinition &&
                d.DependencyType.GetGenericTypeDefinition() != typeof(IEnumerable <>) &&
                !enumerableDependencies.Contains(d));

            var availableGenericDependencies =
                availableServices.Keys.Where(
                    d => d?.DependencyType != null && d.DependencyType.IsGenericTypeDefinition &&
                    d.DependencyType.GetGenericTypeDefinition() != typeof(IEnumerable <>)).ToArray();

            var satisfiableGenericDependencies = genericDependencies.Where(d => d?.DependencyType != null &&
                                                                           availableGenericDependencies.Any(
                                                                               ad =>
                                                                               ad.DependencyType ==
                                                                               d.DependencyType
                                                                               .GetGenericTypeDefinition()))
                                                 .ToArray();

            foreach (var dependency in satisfiableGenericDependencies)
            {
                var dependencyType = dependency.DependencyType;
                var typeDefinition = dependencyType.GetGenericTypeDefinition();
                var typeArguments  = dependencyType.GenericTypeArguments;

                var availableMatchingPoints =
                    availableGenericDependencies.Where(d => d.DependencyType == typeDefinition)
                    .Select(d => availableServices[d] as GenericType)
                    .ToArray();

                foreach (var point in availableMatchingPoints)
                {
                    var newPoint = new GenericTypeInstantiation(dependency, point.Constructor, typeArguments);
                    availableServices[dependency] = newPoint;
                }
            }

            // Update the map with the injected generic services
            ResolveFrom(pointsGroupedByDependency, availableServices);
        }
Beispiel #2
0
        private static void ResolveGenericDependencies(IEnumerable<IDependency> unresolvedDependencies,
            IEnumerable<IDependency> enumerableDependencies, IDictionary<IDependency, IInstantiationPoint> availableServices,
            IDictionary<IDependency, ICollection<IInstantiationPoint>> pointsGroupedByDependency)
        {
            var genericDependencies = unresolvedDependencies.Where(
                d => d?.DependencyType != null &&
                     d.DependencyType.IsGenericType && !d.DependencyType.IsGenericTypeDefinition &&
                     d.DependencyType.GetGenericTypeDefinition() != typeof(IEnumerable<>) &&
                     !enumerableDependencies.Contains(d));

            var availableGenericDependencies =
                availableServices.Keys.Where(
                    d => d?.DependencyType != null && d.DependencyType.IsGenericTypeDefinition &&
                         d.DependencyType.GetGenericTypeDefinition() != typeof(IEnumerable<>)).ToArray();

            var satisfiableGenericDependencies = genericDependencies.Where(d => d?.DependencyType != null &&
                                                                                availableGenericDependencies.Any(
                                                                                    ad =>
                                                                                        ad.DependencyType ==
                                                                                        d.DependencyType
                                                                                            .GetGenericTypeDefinition()))
                .ToArray();

            foreach (var dependency in satisfiableGenericDependencies)
            {
                var dependencyType = dependency.DependencyType;
                var typeDefinition = dependencyType.GetGenericTypeDefinition();
                var typeArguments = dependencyType.GenericTypeArguments;

                var availableMatchingPoints =
                    availableGenericDependencies.Where(d => d.DependencyType == typeDefinition)
                        .Select(d => availableServices[d] as GenericType)
                        .ToArray();

                foreach (var point in availableMatchingPoints)
                {
                    var newPoint = new GenericTypeInstantiation(dependency, point.Constructor, typeArguments);
                    availableServices[dependency] = newPoint;
                }
            }

            // Update the map with the injected generic services
            ResolveFrom(pointsGroupedByDependency, availableServices);
        }