canton7 / Stylet

A very lightweight but powerful ViewModel-First MVVM framework for WPF for .NET Framework and .NET Core, inspired by Caliburn.Micro.
MIT License
988 stars 143 forks source link

EventAggregator: publishing with multiple channels not work as expected #127

Closed wakuflair closed 4 years ago

wakuflair commented 4 years ago

Hi

I use EventAggregator to publish an event, it works well with one channel, but when I specify two channels, the event cann't be triggered. Here's the code:

    public class ShellViewModel : Screen
    {
        public ShellViewModel(IEventAggregator eventAggregator)
        {
            new A(eventAggregator);
            // eventAggregator.Publish("Hello", "AChanel"); // This is ok
            eventAggregator.Publish("Hello", "AChanel", "BChanel"); // This can't trigger
        }
    }

    public class A : IHandle<string>
    {
        public A(IEventAggregator eventAggregator)
        {
           eventAggregator.Subscribe(this, "AChanel"); 
        }
        public void Handle(string message)
        {
            MessageBox.Show(message);
        }
    }

I noticed that If I Subscribe(this, "AChanel", "BChanel"), it can work. But it's weired using channel like this, because I only care about "AChanel".

canton7 commented 4 years ago

Right you are: this should be Any, not All:

https://github.com/canton7/Stylet/blob/9675bc5d9b00fff7eafc49f682a34c004a6f1dab/Stylet/EventAggregator.cs#L186

canton7 commented 4 years ago

Apologies for the delay fixing this