public IConsumerRegistrationConfigurator <T> AddConsumer <T>(Type consumerDefinitionType, Action <IConsumerConfigurator <T> > configure = null)
            where T : class, IConsumer
        {
            if (TypeMetadataCache <T> .HasSagaInterfaces)
            {
                throw new ArgumentException($"{TypeMetadataCache<T>.ShortName} is a saga, and cannot be registered as a consumer", nameof(T));
            }

            IConsumerRegistration ValueFactory(Type type)
            {
                ConsumerRegistrationCache.Register(type, Registrar);

                return(new ConsumerRegistration <T>());
            }

            var registration = _consumers.GetOrAdd(typeof(T), ValueFactory);

            registration.AddConfigureAction(configure);

            if (consumerDefinitionType != null)
            {
                ConsumerDefinitionRegistrationCache.Register(consumerDefinitionType, Registrar);
            }

            return(new ConsumerRegistrationConfigurator <T>(this));
        }
Beispiel #2
0
        void IRegistrationConfigurator.AddConsumer(Type consumerType, Type consumerDefinitionType)
        {
            if (TypeMetadataCache.HasSagaInterfaces(consumerType))
                throw new ArgumentException($"{TypeMetadataCache.GetShortName(consumerType)} is a saga, and cannot be registered as a consumer",
                    nameof(consumerType));

            IConsumerRegistration ValueFactory(Type type)
            {
                ConsumerRegistrationCache.Register(type, _containerRegistrar);

                if (consumerDefinitionType != null)
                    ConsumerDefinitionRegistrationCache.Register(consumerDefinitionType, _containerRegistrar);

                return (IConsumerRegistration)Activator.CreateInstance(typeof(ConsumerRegistration<>).MakeGenericType(type));
            }

            _consumerRegistrations.GetOrAdd(consumerType, ValueFactory);
        }