You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any way to use notifications with generics? I have this:
publicsealedrecordApprovedNotification<T>(TChecklist):INotificationwhereT:IChecklist;publicsealedclass NotificationHandler<T>:INotificationHandler<ApprovedNotification<T>>where T : IChecklist
When I send the notification, the handler is never called. I'm guessing I need to do some type of explicit registration?
The text was updated successfully, but these errors were encountered:
You can use generics out of the box in almost the same way:
publicrecordApprovedNotification<T>(TChecklist):INotificationwhereT:IChecklist;publicsealedclassNotificationHandler<T>:INotificationHandler<T>whereT:ApprovedNotification<IChecklist>{public Task Handle(Tnotification,CancellationTokencancellationToken){// Do stuffreturn Task.CompletedTask;}}
The differences:
The notification type can't be sealed due to boxing/unboxing constraints
The handler needs to the type of the notification, not the type inside the notification, though you can specify that it handles only notifications of the specified type you're looking for
Is there any way to use notifications with generics? I have this:
When I send the notification, the handler is never called. I'm guessing I need to do some type of explicit registration?
The text was updated successfully, but these errors were encountered: