Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Domain event handlers are fired multiple times in case of registering multiple handlers for the same domain event. #152

Open
CanerPatir opened this issue Jun 28, 2018 · 0 comments
Labels
Milestone

Comments

@CanerPatir
Copy link

CanerPatir commented Jun 28, 2018

test case like following

 public class EventHandlerTests  
    {
        [Fact]
        public void should_work()
        {
            var resolver = IocBuilder.New.UseAutofacContainerBuilder()
                .UseStoveWithNullables(typeof(FakeBootstrapper)).UseStoveEventBus()
                .RegisterServices(s =>
                {
                    s.RegisterType<FakeBootstrapper>();
                    s.RegisterType<FakeSendToImageProcessorEventHandler>();
                    s.RegisterType<FakeVisualMappingCompletedEventHandler>();
                })
                .CreateResolver();


            var eventBus = resolver.Resolve<IEventBus>();

            eventBus.Register(typeof(VisualMappingCompletedEvent), new IocHandlerFactory(resolver, typeof(FakeSendToImageProcessorEventHandler)));

            eventBus.Register(typeof(VisualMappingCompletedEvent), new IocHandlerFactory(resolver, typeof(FakeVisualMappingCompletedEventHandler)));

            eventBus.Publish<VisualMappingCompletedEvent>(new VisualMappingCompletedEvent(), new Headers());
        }
    }


    public class FakeSendToImageProcessorEventHandler : EventHandlerBase, IEventHandler<VisualMappingCompletedEvent>, ITransientDependency
    {
        static int a ;
        public void Handle(VisualMappingCompletedEvent @event, Headers headers)
        {
            a++;
        }
    }

    public class FakeVisualMappingCompletedEventHandler : EventHandlerBase, IEventHandler<VisualMappingCompletedEvent>, ITransientDependency
    {
        static int b;
        public void Handle(VisualMappingCompletedEvent @event, Headers headers)
        {
            b++;
        }
    }

    public class FakeBootstrapper : StoveBootstrapper
    {

    }

In this case you will see a = 2, b = 2

@CanerPatir CanerPatir changed the title Domain event handlers are fired multiple times in case of register multiple handlers for the same domain event. Domain event handlers are fired multiple times in case of registering multiple handlers for the same domain event. Jun 28, 2018
@osoykan osoykan added this to the 2.4.1 milestone Jun 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants