1

I'm trying to figure out what is the best approach to pass event from low level project to UI layer, for example - UI references project A, project A references project B etc.

When some edge case happens on project B I want to show a warning on the UI (not to throw exception and not to return any value).

So I thought events could be a solution.

I have to handle the event at the UI level, but to raise it from project B. The UI can't subscribe to project B's event handler because it doesn't reference it, so the only options I see is pass the event all around (from UI to project A, from A to B etc.) or use a static event.

What is the optimal and cleanest way to achieve this?

Patrick
  • 5,526
  • 14
  • 64
  • 101
BornToCode
  • 9,495
  • 9
  • 66
  • 83
  • 1
    Shared message bus might be a solution. You pass that down to A then to B (or store in static property if you are fine with that). Then anyone can post messages there and anyone can subscribe to them. So project B might post UINotification message (you create that yourself) and UI might subscribe to that and show notification. – Evk Oct 25 '17 at 12:05
  • When software is running there are no such things as *project A* or *B*. There are [assemblies](https://stackoverflow.com/q/2089575/1997232), [dlls](https://stackoverflow.com/q/33284616/1997232), [classes](https://stackoverflow.com/q/2559583/1997232), etc. And such questions were asked 100500 times already. I personally like the idea of logging into sqlite and simply polling the log by window which displays warnings from different sources. – Sinatr Oct 25 '17 at 12:25
  • @Sinatr - When writing code there are things as project A and project B and that's what my question is all about (writing code). I did try to search on Stackoverflow and wasn't sure I could find an ideal solution (what I found was only about static event handlers which might lead to memory leaks if not written correctly) so I wrote the question to see if anyone has another idea - and actually I got a response to a relevant idea I didn't thought about before - using a message bus (Evk's comment). – BornToCode Oct 25 '17 at 13:02

0 Answers0