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>());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenGenericDecoratorRegistrationSource"/> class.
        /// </summary>
        /// <param name="registrationData">The registration data for the open generic.</param>
        /// <param name="existingPipelineBuilder">The pipeline for the existing open generic registration.</param>
        /// <param name="activatorData">The activator data.</param>
        public OpenGenericDecoratorRegistrationSource(
            RegistrationData registrationData,
            IResolvePipelineBuilder existingPipelineBuilder,
            OpenGenericDecoratorActivatorData activatorData)
        {
            if (registrationData == null)
            {
                throw new ArgumentNullException(nameof(registrationData));
            }

            if (activatorData == null)
            {
                throw new ArgumentNullException(nameof(activatorData));
            }

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

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

            _registrationData = registrationData;
            _activatorData    = activatorData;
            _existingPipeline = existingPipelineBuilder;
        }
示例#3
0
        public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <IComponentRegistration> > registrationAccessor)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (registrationAccessor == null)
            {
                throw new ArgumentNullException(nameof(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));
            }
        }
        /// <inheritdoc/>
        public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <ServiceRegistration> > registrationAccessor)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            if (registrationAccessor == null)
            {
                throw new ArgumentNullException(nameof(registrationAccessor));
            }

            if (OpenGenericServiceBinder.TryBindOpenGenericService(service, _registrationData.Services, _activatorData.ImplementationType, out Type? constructedImplementationType, out Service[]? 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);
     this._registrationData = registrationData;
     this._activatorData    = activatorData;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenGenericRegistrationSource"/> class.
        /// </summary>
        /// <param name="registrationData">The registration data for the open generic.</param>
        /// <param name="existingPipelineBuilder">The pipeline for the existing open generic registration.</param>
        /// <param name="activatorData">The activator data.</param>
        public OpenGenericRegistrationSource(
            RegistrationData registrationData,
            IResolvePipelineBuilder existingPipelineBuilder,
            ReflectionActivatorData activatorData)
        {
            if (registrationData == null)
            {
                throw new ArgumentNullException(nameof(registrationData));
            }

            if (activatorData == null)
            {
                throw new ArgumentNullException(nameof(activatorData));
            }

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

            _registrationData        = registrationData;
            _existingPipelineBuilder = existingPipelineBuilder;
            _activatorData           = activatorData;
        }
        /// <inheritdoc/>
        public IEnumerable <IComponentRegistration> RegistrationsFor(Service service, Func <Service, IEnumerable <ServiceRegistration> > registrationAccessor)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            if (registrationAccessor == null)
            {
                throw new ArgumentNullException(nameof(registrationAccessor));
            }

            if (OpenGenericServiceBinder.TryBindOpenGenericDelegate(service, _registrationData.Services, _activatorData.Factory, out var constructedFactory, out Service[]? services))
            {
                // Pass the pipeline builder from the original registration to the 'CreateRegistration'.
                // So the original registration will contain all of the pipeline stages originally added, plus anything we want to add.
                yield return(RegistrationBuilder.CreateRegistration(
                                 Guid.NewGuid(),
                                 _registrationData,
                                 new DelegateActivator(typeof(object), constructedFactory),
                                 _existingPipelineBuilder,
                                 services));
            }
        }
示例#8
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;
        }