public void Subscribe(Type consumer, Action <ConsumerSetup> conf = null) { var consumerType = consumer.GetInterfaces() .Where(x => x.IsGenericType) .Select(x => new { Definition = x.GetGenericTypeDefinition(), GenericArgs = x.GetGenericArguments(), Type = x }) .Where(x => x.GenericArgs.Length == 1) .FirstOrDefault(x => x.Definition == typeof(IConsumer <>)); if (consumerType == null) { throw new Exception($"is this a IConsumer<>, {consumer}"); } var consumerSetup = new ConsumerSetup() { ConsumerType = consumer, MessageType = consumerType.GenericArgs[0] }; conf?.Invoke(consumerSetup); Subscribe(consumerSetup); }
public void Subscribe(ConsumerSetup setup) { Consumers.Add(setup); }