The definition and application of Services in the Prism world

Topics: Prism v1, Prism v2 - Silverlight 2, Prism v2 - Silverlight 3, Prism v2 - WPF 3.5, Prism v2 - WPF 4, Prism v4 - Silverlight 4, Prism v4 - WPF 4
Mar 16, 2011 at 5:58 PM

Prism documentation uses the term service often, which is a pretty general term.  From the Prism examples a service seems to most often provide an interface to the Model Class.  In this case the Model itself becomes nothing more than a class to hold the data and the service does all the data access and validation.  In a general sense I think of a service as any functionality (methods) exposed externally through an interface.

1) When should I employ a service to access the Data instead of just using the Model within the MVVM pattern?

2)  What is a good definition for a service in the Prism world?  I am looking for a deterministic way to determine when I should create a service.


Mar 16, 2011 at 8:38 PM


From the description of the Model class in the MVVM chapter of the Prism MSDN documentation:

"The model in the MVVM pattern encapsulates business logic and data. Business logic is defined as any application logic that is concerned with the retrieval and management of application data and for making sure that any business rules that ensure data consistency and validity are imposed. To maximize re-use opportunities, models should not contain any use case–specific or user task–specific behavior or application logic."

Therefore, if you need to expose certain functionality or use case that would be consumed from other components under a certain interface, you could encapsulate it into a service. Prism provides the means to share that service (you can read more about it in the Shared Services section inside the Communication chapter of the Prism MSDN documentation) across different modules. The decision on whether to use a service or not depends on your requirements and preference for the architecture of your application.

I hope you find this helpful.

Guido Leandro Maliandi