public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (registrationAccessor == null)
            {
                throw new ArgumentNullException("registrationAccessor");
            }

            Type constructedImplementationType;
            IEnumerable <Service> services;

            if (OpenGenericServiceBinder.TryBindServiceType(service, _registrationData.Services, _activatorData.ImplementationType, out constructedImplementationType, out services))
            {
                var swt         = (IServiceWithType)service;
                var fromService = _activatorData.FromService.ChangeType(swt.ServiceType);

                return(registrationAccessor(fromService)
                       .Select(cr => RegistrationBuilder.CreateRegistration(
                                   Guid.NewGuid(),
                                   _registrationData,
                                   new ReflectionActivator(
                                       constructedImplementationType,
                                       _activatorData.ConstructorFinder,
                                       _activatorData.ConstructorSelector,
                                       AddDecoratedComponentParameter(swt.ServiceType, cr, _activatorData.ConfiguredParameters),
                                       _activatorData.ConfiguredProperties),
                                   services)));
            }

            return(Enumerable.Empty <IComponentRegistration>());
        }
        public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (registrationAccessor == null)
            {
                throw new ArgumentNullException("registrationAccessor");
            }

            Type constructedImplementationType;
            IEnumerable <Service> services;

            if (OpenGenericServiceBinder.TryBindServiceType(service, _registrationData.Services, _activatorData.ImplementationType, out constructedImplementationType, out services))
            {
                yield return(RegistrationBuilder.CreateRegistration(
                                 Guid.NewGuid(),
                                 _registrationData,
                                 new ReflectionActivator(
                                     constructedImplementationType,
                                     _activatorData.ConstructorFinder,
                                     _activatorData.ConstructorSelector,
                                     _activatorData.ConfiguredParameters,
                                     _activatorData.ConfiguredProperties),
                                 services));
            }
        }
        public OpenGenericRegistrationSource(
            RegistrationData registrationData,
            ReflectionActivatorData activatorData)
        {
            if (registrationData == null)
            {
                throw new ArgumentNullException("registrationData");
            }
            if (activatorData == null)
            {
                throw new ArgumentNullException("activatorData");
            }

            OpenGenericServiceBinder.EnforceBindable(activatorData.ImplementationType, registrationData.Services);

            _registrationData = registrationData;
            _activatorData    = activatorData;
        }
        public OpenGenericDecoratorRegistrationSource(
            RegistrationData registrationData,
            OpenGenericDecoratorActivatorData activatorData)
        {
            if (registrationData == null)
            {
                throw new ArgumentNullException("registrationData");
            }
            if (activatorData == null)
            {
                throw new ArgumentNullException("activatorData");
            }

            OpenGenericServiceBinder.EnforceBindable(activatorData.ImplementationType, registrationData.Services);

            if (registrationData.Services.Contains((Service)activatorData.FromService))
            {
                throw new ArgumentException(string.Format(
                                                "The service {0} cannot be both the adapter's from and to parameters - these must differ.", activatorData.FromService));
            }

            _registrationData = registrationData;
            _activatorData    = activatorData;
        }
Beispiel #5
0
        public OpenGenericDecoratorRegistrationSource(
            RegistrationData registrationData,
            OpenGenericDecoratorActivatorData activatorData)
        {
            if (registrationData == null)
            {
                throw new ArgumentNullException("registrationData");
            }
            if (activatorData == null)
            {
                throw new ArgumentNullException("activatorData");
            }

            OpenGenericServiceBinder.EnforceBindable(activatorData.ImplementationType, registrationData.Services);

            if (registrationData.Services.Contains((Service)activatorData.FromService))
            {
                throw new ArgumentException(string.Format(
                                                OpenGenericDecoratorRegistrationSourceResources.FromAndToMustDiffer, activatorData.FromService));
            }

            _registrationData = registrationData;
            _activatorData    = activatorData;
        }