This post originated from an RSS feed registered with .NET Buzz
by Udi Dahan.
Original Post: Decoupling layers - upside down
Feed Title: Udi Dahan - The Software Simplist
Feed URL: http://feeds.feedburner.com/UdiDahan-TheSoftwareSimplist
Feed Description: I am a software simplist. I make this beast of architecting, analysing, designing, developing, testing, managing, deploying software systems simple.
This blog is about how I do it.
Every once in a while I run into a question about how code from a "lower layer" can call code in an "upper layer". This comes up a lot around the DDD groups where you see people trying to work around the idea that repositories are above entities when they want/need an entity to call into a repository. Same thing in data access.
Why is it not yet obvious that events (in .net) are the solution?
Just have your "lower layer" objects expose events for what they need from "upper layers" and have objects there register for those events. In the event-handling methods the calls can be made between objects on the upper layer finally returning the result back to the lower layer. As an aside, a lot of people aren't used to the fact that raising an event can return something - it really is quite useful.