protected IDisposable RegisterAllHandlersByReflection(object eventHandler)
        {
            SubscriptionDisposer subscriptionDisposer = new SubscriptionDisposer(this);

            this.RegisterAllEventHandlersByReflection(eventHandler, subscriptionDisposer);
            this.RegisterAllCommandHandlersByReflection(eventHandler, subscriptionDisposer);
            return(subscriptionDisposer);
        }
 private void RegisterTheCreatedAction(Type handlerType, object action, SubscriptionDisposer subscriptionDisposer)
 {
     registerMethod.MakeGenericMethod(handlerType).Invoke(this, new[]
     {
         action,
         subscriptionDisposer
     });
 }
        private void RegisterAllCommandHandlersByReflection(object handler, SubscriptionDisposer subscriptionDisposer)
        {
            IEnumerable <Type> handlerTypes = handler.GetType().GetInterfaces().Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICommandHandler <>));

            foreach (Type handlerType in handlerTypes)
            {
                this.RegisterCommandHandler(handlerType, handler, subscriptionDisposer);
            }
        }
        private void RegisterEventHandler(Type handleEventType, object eventHandler, SubscriptionDisposer subscriptionDisposer)
        {
            createActionMethod = this.GetType().GetMethod("CreatePublishAction");
            registerMethod     = this.GetType().GetMethod("RegisterEventHandler");
            var genericArgs = handleEventType.GetGenericArguments();

            foreach (var genericArg in genericArgs)
            {
                var action = this.CreateTheProperAction(genericArg, eventHandler);
                this.RegisterTheCreatedAction(genericArg, action, subscriptionDisposer);
            }
        }
        private void RegisterHandler <T>(Action <T> handler, SubscriptionDisposer subscriptionDisposer) where T : IMessage
        {
            Dictionary <Guid, Action <IMessage> > handlers;

            if (!this.routes.TryGetValue(typeof(T), out handlers))
            {
                handlers = new Dictionary <Guid, Action <IMessage> >();
                this.routes.Add(typeof(T), handlers);
            }

            Guid handlerID = Guid.NewGuid();
            Action <IMessage> adjustedHandler = DelegateAdjuster.CastArgument <IMessage, T>(x => handler(x));

            handlers.Add(handlerID, adjustedHandler);
            subscriptionDisposer.AddHandler(typeof(T), handlerID);
        }
 public void RegisterEventHandler <T>(Action <T> handler, SubscriptionDisposer subscriptionDisposer) where T : IDomainEvent
 {
     this.RegisterHandler <T>(handler, subscriptionDisposer);
 }
 public void RegisterCommandHandler <T>(Action <T> handler, SubscriptionDisposer subscriptionDisposer) where T : ICommand
 {
     this.RegisterHandler <T>(handler, subscriptionDisposer);
 }