开发者

Where to put the calls to WCF or other webservices in MVVM?

开发者 https://www.devze.com 2022-12-12 02:31 出处:网络
I\'m building Silverlight applicaitions using Prism and MVVM. When calling WCF serv开发者_运维问答ices on your own server, or even external webservices like the Bing api, would this be done from the

I'm building Silverlight applicaitions using Prism and MVVM.

When calling WCF serv开发者_运维问答ices on your own server, or even external webservices like the Bing api, would this be done from the Model? or from the ViewModel, thus making the service the Model?


Yes. The View should only manage the transformation of data into user interface elements, the Controller should only orchestrate the interaction between views and model, and the remaining (business logic and data access, this one including calls to remote services) should be in the Model.


Sorskoot,

For your scenario, I create a Services class that interfaces with WCF. My ViewModels then interface with service.

Also, with silverlight introducing Silverlight 4, you may want to create your own models and use converters to convert the WCF objects going into your app so you have a level of separation. Plus you can start utilizing features such as IDataErrorInfo, INotifyPropertyChanged.

Search on Cinch. It's not Silverlight compatible but will give you an idea of what I'm referring too. Look at DataWrappers.

0

精彩评论

暂无评论...
验证码 换一张
取 消