/// <summary> /// Constructor that gets the finder of methods marked with specific atrributes. /// </summary> /// <param name="finder"></param> public EventBus(IHandlerFindingStrategy finder) { //TODO : readerwriterlockslim , conccurentdictionary. //Replace with ninject tools. this.finder = finder; handlersByType = HashMultiMap <Type, EventHandler> .Create(); handlersByTypeLock = new ReaderWriterLockSlim(); eventsToDispatch = new ThreadLocal <Queue <EventWithHandler> >(() => { return(new Queue <EventWithHandler>()); }); isDispatching = new ThreadLocal <Boolean>(() => { return(false); }); }
/// <summary> /// This getting an object and extract all the methods marked with Subscribe attribute. /// </summary> /// <param name="subscriber">The object whose methods are desired to be event handlers</param> /// <returns>MultiMap between a key which is event type and a value which is the event handler contains a target object and methodInfo</returns> public IMultiMap <Type, EventHandler> FindAllHandlers(Object subscriber) { IMultiMap <Type, EventHandler> methodsInSubscriber = HashMultiMap <Type, EventHandler> .Create(); foreach (MethodInfo method in GetMarkedMethods(subscriber)) { ParameterInfo[] parmetersTypes = method.GetParameters(); Type eventType = parmetersTypes[0].ParameterType; EventHandler handler = new EventHandler(subscriber, method); methodsInSubscriber.Add(eventType, handler); } return(methodsInSubscriber); }