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(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); }
static bool IsConsumerOrDefinition(Type type) { return(TypeMetadataCache.HasConsumerInterfaces(type) && !TypeMetadataCache.HasSagaInterfaces(type) || type.HasInterface(typeof(IConsumerDefinition <>))); }
static bool IsSagaTypeOrDefinition(Type type) { return(TypeMetadataCache.HasSagaInterfaces(type) || type.HasInterface(typeof(ISagaDefinition <>))); }