Esempio n. 1
0
        public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor)
        {
            var typedService = service as TypedService;

            if (typedService == null ||
                typedService.ServiceType.IsGenericType && typedService.ServiceType.GetGenericTypeDefinition() == typeof(IEnumerable <>) ||
                typedService.ServiceType.IsArray ||
                typeof(IStartable).IsAssignableFrom(typedService.ServiceType))
            {
                yield break;
            }

            if (typedService.ServiceType == this.ResolvedType)
            {
                foreach (var reg in concretesSource.RegistrationsFor(service, registrationAccessor))
                {
                    yield return(reg);
                }
            }
            else
            {
                var rb = RegistrationBuilder.ForDelegate((c, p) => CreateMock(c, typedService))
                         .As(service)
                         .InstancePerLifetimeScope();

                yield return(rb.CreateRegistration());
            }
        }
Esempio n. 2
0
        public void IgnoresTypesThatShouldNotBeProvided(Type serviceType)
        {
            var source  = new AnyConcreteTypeNotAlreadyRegisteredSource();
            var service = new TypedService(serviceType);

            Assert.False(source.RegistrationsFor(service, s => Enumerable.Empty <IComponentRegistration>()).Any(), $"Failed: {serviceType}");
        }