/// <summary> /// 配置consumer /// </summary> /// <param name="cfg">配置</param> /// <param name="consumers">consumer类型集合</param> public void Configure(SubscriptionBusServiceConfigurator cfg, List <Type> consumers) { InitAOPConsumer(); Log.Write(string.Format("消费类型{0}个", consumers.Count), MessageType.Info); foreach (var consumer in consumers) { Log.Write(consumer.FullName, MessageType.Debug); if (consumer.IsGenericType) { Log.Write(string.Format("跳过{0}因为是泛型", consumer.FullName), MessageType.Warn); continue; } var consumerTypes = consumer.GetInterfaces() .Where(d => d.IsGenericType && d.GetGenericTypeDefinition() == typeof(IEventConsumer <>)) .Select(d => d.GetGenericArguments().Single()) .Distinct(); foreach (var eventConsumerType in consumerTypes) { try { Log.Write(string.Format("{0} map {1}", consumer.FullName, eventConsumerType.FullName), MessageType.Debug); var type = consumer; this.FastInvoke(new[] { eventConsumerType, consumer }, x => x.ConsumerTo <Event, IEventConsumer <Event> >(cfg, type), cfg, consumer); } catch (Exception ex) { Log.Write(ex.Message, MessageType.Error, this.GetType(), ex); } } } cfg.Success("配置Consumer成功"); }