I have a set of collaborating objects and I would like to keep this structure intact because of separation of concerns, principle of single responsibly, and test-ability.
The challenge I am having is how to best handle asynchronous events up the chain.
Here is my scenario:
ObjectA reference ObjectB references ObjectC references ObjectD.
ObjectA makes a call to ObjectB and so on which ultimately results in ObjectD making an asynchronous call to an external system.
Question: I am looking for recommended best practices how to have ObjectA make a non-blocking call and then being notified of the async completed result from ObjectD.
I have it working with passing and chaining event handlers down the layers but this seems overly complex and I am concerned about performance.
Any suggestings on how to better handle this?
Thanks.
It sounds like you might benefit from something like EventAggregator.Net. It allows you to subscribe to events of different types without having to worry about who publishes the event. In other words ObjectA subscribes to an OperationCompleted event which is published by ObjectD, but ObjectA never had a reference to ObjectD or knew it existed.