开发者

Is having an instance of serviceclient at every viewmodel a good idea?

I have to refactor an application which has at almost every model and codebehind file an instance of serviceclient, and some of them use a serviceclient property from App.xaml.cs (Silverlight 4)

What is the best practice for this? Do it so, that all controls would use an instance of serviceclient kept in app.xaml.cs, or create at every viewmodel开发者_运维问答/codebehind an instance of serviceClient?

In coming few weeks (as I get an answer for my other question also) I need to write some unitests, so I need to keep this in mind.


As a best practice and a very hands-on approach to doing SL, MVVM and WCF, I would like to invite you to read and follow http://aviadezra.blogspot.com/2010/10/silverlight-mvvm-odata-wcf-data.html. Just perform this tutorial like steps and you will know how to perform your job.

Very specifically, about your question on where to create and maintain your service reference, the suggested approach is to create a static object called something like DalService that will be instanciated on first usage and just hang around and be available for any viewmodel to query the back-end.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜