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)); }
public IConsumerRegistrationConfigurator 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)); } return(ConsumerRegistrationCache.AddConsumer(this, consumerType, consumerDefinitionType)); }
void IRegistrationConfigurator.AddConsumer <T>(Action <IConsumerConfigurator <T> > configure) { 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, _containerRegistrar); return(new ConsumerRegistration <T>()); } var configurator = _consumerConfigurations.GetOrAdd(typeof(T), ValueFactory); configurator.AddConfigureAction(configure); }
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); }