views:

41

answers:

1

Perhaps this is a very basic question, please pardon me if it is --- I'm a beginner in C#.

I have a WPF GUI for sending commands to a receiver. The commands are ASCII texts. Now, I separated the communication part into a separate project because I have console applications that use the communication methods in addition to the GUI. The communication DLL uses async methods on normal sockets.

Now the problem is that I will have a circular dependency. The GUI needs to call communication routines to send messages, and the routines need to call GUI to show the responses. I understand that I could make an interface which the communication inherits and get around the dependency, but is this the best way to do this? Or is this a flaw in my design? I basically wanted to decouple the GUI from the underlying communication layer.

Thanks a lot for the help!

+1  A: 

Your library (dll) shouldn't update the GUI directly. You should have it raise events. Ideally the events would be at a higher level of abstraction as well ("Message Received Successfully" rather than "Packet Received Successfully", but it's really up to you how much of the low level functionality of the library you want to expose)

The GUI (or console app or a completely different library) can now subscribe to the events and access the event data. The GUI, as a higher layer knows about the library, but the library shouldn't know about the GUI (or the console appliation)

Chaitanya