/// <summary> /// 初始化同步消息总线 /// </summary> private void InitializeSyncMessageBus(params Assembly[] assemblies) { DependencyResolver.RegisterTypes(x => TypeUtils.IsSyncSubscriber(x), assemblies); var messageBus = DependencyResolver.Resolve <ISyncMessageBus>(); messageBus.Initialize(); messageBus.RegisterAllSubscribersInAssemblies(assemblies); messageBus.Start(); }
void IMessageBus.RegisterAllSubscribersInAssemblies(params Assembly[] assemblies) { var bus = this as ISyncMessageBus; foreach (var assembly in assemblies) { foreach (var subscriberType in assembly.GetTypes().Where(t => TypeUtils.IsSyncSubscriber(t))) { bus.RegisterSubscriber(subscriberType); } } }
void IMessageBus.RegisterSubscriber(Type subscriberType) { if (!TypeUtils.IsSyncSubscriber(subscriberType)) { throw new EventSourcingException( "类型‘{0}’不是一个有效的消息订阅者,订阅者必须至少具有一个标记了SyncHandler特性的方法。", subscriberType.FullName); } _messageHandlerMetaDataManager.RegisterMetaDatasFromType( subscriberType, (handler, attribute) => new HandlerMetaData { Handler = handler, SubscriberType = subscriberType }); }