Home  /  Questions  /  Question

100   96.6
Jul 18, 2010

Where to place events from service layer in MVP?

I am coding a GUI that communicates via TCP/IP with Automated Guided Vehicles (AGVs).

The Model communicates with TCP/IP Service layer.
I was thinking of letting the Presenter subscribe to the TCP/IP events?

But is this the best solution?
After receiving the events the View should be updated.

Any suggestions are appreciated.

60   95.3
Jul 19, 2010
You can probably use a repository pattern/layer to abstract out that service layer calls... and call it within the presenter.

You can use Action<T>/Func<T>/Predicate<T> delegates to subscribe to the events and handle it in the presenter.

just my two cents

100   96.6
Jul 19, 2010
Joshua, thanks for your answer :-)
I think my problem is that I have 2 Presenters.
I want both Presenters to subscribe to the TCP/IP events.
The instance of TCP/IP Service layer is created in the Model.
Do I have to pass the functions that should be called in the 2 Presenters to the Model?
Or maybe I should create the TCP/IP Service layer in the base class for all Presenter classes
and then pass it to the Model?

100   96.6
Jul 21, 2010
My solution for the time being:

The Model creates an instance of TCP/IP Service and calls the TCP/IP Service layer.

The different Presenters subscribes to relevant TCP/IP events and updates the View.

To avoid passing of functions (or other problems) I have implemented the TCP/IP Service as a Singleton.

I anyone knows of good examples/articles on how to handle events from a non Microsoft service layer in MVP,
please post a link here.