Not a help question per say, so hope it'
# social
a
Not a help question per say, so hope it's okay to asking here. What type would you expect being broadcast when running the code below?
MyNotification
or
IMyNotification
? Please answer in a ๐Ÿงต
Copy code
csharp
@{

    var notification = new MyNotification();

    EventAggregator.Publish<IMyNotification>(notification);

    <pre>Yay</pre>

}
j
I'd expect IMyNotification as that is what it specifies in the publish method ๐Ÿคทโ€โ™‚๏ธ
a
I would too. I think it used to work like this at some point. I'm pretty sure I tested this for Skybrud Redirects a while back. But I've jused spent some time testing this in different versions of Umbraco now (9, 10, 12, 13 and 14), and the notification handler has to be for
MyNotification
to be hit. Given the code below, only
MyNotificationHandler2
is hit ๐Ÿค” ๐Ÿ™ƒ
Copy code
csharp
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;

namespace Umbraco13.Features.Notifications;

public class NotificationsComposer : IComposer {
    public void Compose(IUmbracoBuilder builder) {
        builder.AddNotificationHandler<IMyNotification, MyNotificationHandler1>();
        builder.AddNotificationHandler<MyNotification, MyNotificationHandler2>();
    }
}

public interface IMyNotification : INotification { }

public class MyNotification : IMyNotification { }

public class MyNotification2 : IMyNotification { }

public class MyNotificationHandler1 : INotificationHandler<IMyNotification> {

    public void Handle(IMyNotification notification) {
        Console.WriteLine("Hello from MyNotificationHandler1: " + notification.GetType());
    }

}

public class MyNotificationHandler2 : INotificationHandler<MyNotification> {

    public void Handle(MyNotification notification) {
        Console.WriteLine("Hello from MyNotificationHandler2: " + notification.GetType());
    }

}
s
Still #1125392773038755890 next time please.
4 Views