在每个视图模型中都有一个 serviceclient 实例是个好主意吗?
我必须重构一个应用程序,该应用程序几乎每个模型和代码隐藏文件都有一个 serviceclient 实例,其中一些使用 App.xaml.cs (Silverlight 4) 中的 serviceclient 属性,
最佳实践是什么?这样做,所有控件都将使用保存在 app.xaml.cs 中的 serviceclient 实例,或者在每个视图模型/代码隐藏中创建 serviceClient 实例吗?
在接下来的几周内(当我也得到其他问题的答案时)我需要编写一些统一测试,所以我需要记住这一点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为进行 SL、MVVM 和 WCF 的最佳实践和非常实用的方法,我想邀请您阅读并遵循 http://aviadezra.blogspot.com/2010/10/silverlight-mvvm-odata-wcf-data.html。只需执行本教程类似的步骤,您就会知道如何执行您的工作。
非常具体地,关于在哪里创建和维护服务引用的问题,建议的方法是创建一个名为 DalService 之类的静态对象,该对象将在第一次使用时实例化,并且可用于任何视图模型来查询后面的内容-结尾。
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.