Beispiel #1
0
 public void Dispose()
 {
     if (_binding != null)
     {
         _binding.Dispose();
     }
 }
Beispiel #2
0
        public void test_clearing_event_handler_completes_pending_events()
        {
            var eventHandler = new EventHandler();
            var hits         = new Dictionary <Guid, int>();
            var keys         = new List <Guid> {
                Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()
            };

            keys.ForEach(i => hits[i] = 0);

            Action <EventTypeA> typeAHandler = ep => { hits[ep.Value] += 1; };
            Action <EventTypeB> typeBHandler = ep => { hits[ep.Value] += 1; };

            EventBinding <EventTypeA> binding = null;
            Action <EventTypeA>       removeBindingHandler = ep =>
            {
                if (binding != null)
                {
                    binding.Dispose();
                }
            };

            eventHandler.AddEventHandler(typeAHandler);
            eventHandler.AddEventHandler(typeAHandler);

            binding = eventHandler.AddEventHandler(removeBindingHandler);

            eventHandler.AddEventHandler(typeAHandler);
            eventHandler.AddEventHandler(typeAHandler);

            eventHandler.AddEventHandler(typeBHandler);

            // Trigger normal events
            eventHandler.Trigger(new EventTypeB()
            {
                Value = keys[0]
            });
            Assert(hits[keys[0]] == 1);

            // Trigger handler that removes itself
            eventHandler.Trigger(new EventTypeA()
            {
                Value = keys[1]
            });
            Assert(hits[keys[1]] == 4);

            // Remaining event handlers still work
            eventHandler.Trigger(new EventTypeA()
            {
                Value = keys[2]
            });
            Assert(hits[keys[2]] == 4);
        }
Beispiel #3
0
        public void Execute <T>(T command, Action <CommandExecutedEvent> onComplete) where T : class, ICommand
        {
            Service.Registry.Bind(command);

            EventBinding <Command.CommandExecutedEvent> binding = null;

            binding = command.EventHandler.AddEventHandler <CommandExecutedEvent>((ep) =>
            {
                if (binding != null)
                {
                    binding.Dispose();
                }
                onComplete(ep);
            });

            Handler <T>().Execute(command);
        }