private void ThrowWhenProviderToRegisterOverlapsWithExistingProvider(
                OpenGenericToInstanceProducerProvider providerToRegister)
            {
                // A provider is a superset of the providerToRegister when it can be applied to ALL generic
                // types that the providerToRegister can be applied to as well.
                var supersetProviders =
                    from provider in this.providers
                    where provider.AppliesToAllClosedServiceTypes ||
                    provider.ImplementationType == providerToRegister.ImplementationType
                    select provider;

                bool providerToRegisterIsSuperset =
                    providerToRegister.AppliesToAllClosedServiceTypes && this.providers.Any();

                if (providerToRegisterIsSuperset || supersetProviders.Any())
                {
                    var overlappingProvider = supersetProviders.FirstOrDefault() ?? this.providers.First();

                    throw new InvalidOperationException(
                              StringResources.AnOverlappingGenericRegistrationExists(
                                  providerToRegister.ServiceType,
                                  overlappingProvider.ImplementationType,
                                  overlappingProvider.IsConditional,
                                  providerToRegister.ImplementationType,
                                  providerToRegister.Predicate != null));
                }
            }
        private void ThrowWhenProviderToRegisterOverlapsWithExistingProvider(
            InstanceProducer producerToRegister)
        {
            // A provider is a superset of the providerToRegister when it can be applied to ALL generic
            // types that the providerToRegister can be applied to as well.
            var overlappingProducers =
                from producer in this.CurrentProducers
                where producer.ImplementationType != null
                where !producer.Registration.WrapsInstanceCreationDelegate
                where !producerToRegister.Registration.WrapsInstanceCreationDelegate
                where producer.ImplementationType == producerToRegister.ImplementationType
                select producer;

            if (overlappingProducers.Any())
            {
                var overlappingProducer = overlappingProducers.FirstOrDefault();

                throw new InvalidOperationException(
                          StringResources.AnOverlappingGenericRegistrationExists(
                              producerToRegister.ServiceType,
                              overlappingProducer.ImplementationType,
                              overlappingProducer.IsConditional,
                              producerToRegister.ImplementationType,
                              producerToRegister.IsConditional));
            }
        }
Beispiel #3
0
 private InvalidOperationException GetAnOverlappingGenericRegistrationExistsException(
     IProducerProvider providerToRegister, IProducerProvider overlappingProvider)
 {
     return(new InvalidOperationException(
                StringResources.AnOverlappingGenericRegistrationExists(
                    providerToRegister.ServiceType,
                    overlappingProvider.ImplementationType,
                    overlappingProvider.IsConditional,
                    providerToRegister.ImplementationType,
                    providerToRegister.IsConditional)));
 }