我很好奇人们构建ViewModel的各种方式以及他们选择该方法的原因.
我可以在这里想到几种方法:
-1.注入的存储库 - 控制器加载模型并映射到ViewModel.在这里,ViewModel构造函数可以采用各种集合来为ex设置.在选择列表中,例如:
public CustomerController(ISomeRepository repository)
{
_repository = repository;
}
public ActionResult Create()
{
CustomerCreateViewModel model = new CustomerCreateViewModel(_repository.GetShipTypes,
_repository.GetStates);
..
..
}
-2.ViewModelBuilder - 在控制器中注入或实例化注入存储库的实例.通过类似的东西调用
>var orderViewModel = orderViewModelBuilder.WithStates().Build(orderId);Run Code Online (Sandbox Code Playgroud)
要么,
var orderViewModel = orderViewModelBuilder.WithStates().Build(orderId);Run Code Online (Sandbox Code Playgroud)
-3.直接在控制器中(无需代码 - 杂乱无章)
-4.一些其他服务(注入或不注入)返回控制器随后映射的域模型或ViewModel(执行此操作的任何人返回未明确命名/注释为ViewModel构建器类的视图模型?)
public JobCreateViewModel BuildJobCreateViewModel(int parentId)
{
JobCreateViewModel model = new JobCreateViewModel();
model.JobStatus = _unitOfWork.JobRepository.GetJobStatuses();
model.States=_unitOfWork.StateRepository.GetAll();
return model;
}
Run Code Online (Sandbox Code Playgroud)
现在回程 - 关于验证您的视图模型 - 您是从基础ViewModel类继承标准验证,还是在所有ViewModel之间复制验证(例如数据注释属性),或者只是依赖于服务器端验证,以便它可以再次验证您的域对象吗?
还有其他人?还有什么更好的?为什么?
编辑 根据下面的链接,我确实找到了Jimmy Bogard关于ViewModels架构的好文章.虽然它没有直接解决上面的问题,但对于来这里查看ViewModel信息的人来说,它是一个很好的参考. http://lostechies.com/jimmybogard/2009/06/30/how-we-do-mvc-view-models/
我有一个现有的WCF服务.我在Visual Studio 2010中为我的Windows Phone应用程序添加了一个引用.参考显示,我看到了检查它的属性时的方法.该服务使用basicHttpBinding.似乎从未生成代理类.我无法引用它(是的 - 我正在检查正确的命名空间)
我知道SlSvcUtil.exe实用程序 - 但应该不再需要了.有关为什么我的代理类没有生成但服务引用存在的想法?
谢谢!
编辑:Wsdl文件如下:
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ProjectManager" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://somesite/ProjectManager/ProjectManager.svc?xsd=xsd0" namespace="http://tempuri.org/" />
<xsd:import schemaLocation="http://somesite/ProjectManager/ProjectManager.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xsd:import schemaLocation="http://somesite/ProjectManager/ProjectManager.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/ProjectManager" />
</xsd:schema>
</wsdl:types>
<wsdl:message name="IProjectManagerService_GetProjectList_InputMessage">
<wsdl:part name="parameters" element="tns:GetProjectList" />
</wsdl:message>
<wsdl:message name="IProjectManagerService_GetProjectList_OutputMessage">
<wsdl:part name="parameters" element="tns:GetProjectListResponse" />
</wsdl:message>
<wsdl:message name="IProjectManagerService_GetProjectFiles_InputMessage">
<wsdl:part name="parameters" element="tns:GetProjectFiles" />
</wsdl:message>
<wsdl:message name="IProjectManagerService_GetProjectFiles_OutputMessage">
<wsdl:part name="parameters" element="tns:GetProjectFilesResponse" />
</wsdl:message>
<wsdl:portType name="IProjectManagerService">
<wsdl:operation … 我见过其他帖子,人们无法加载"我的销售工具",而我碰巧在同一条船上.
支持尚未响应,我希望星期一将Windows 8/Paypal API集成从http://paypal.github.io/Windows8SDK/ 进入WinRT应用程序 - 因此转向可能最喜欢的网络社区,堆栈溢出:)
上面的链接提供了一个允许第三方访问的沙箱帐户,因此尝试添加该帐户以允许第三方访问,但甚至无法提供销售工具来执行此操作.我能够从我的主登录中调出销售工具,但不能从沙箱登录中调出.
一旦我登录到沙盒环境并尝试访问"我的销售工具",它就会挂起.浏览器无关紧要,跨浏览器的结果相同.我没有得到任何回报,但等待图像.实际上,左侧的任何东西都不仅仅是销售工具.我整天都试过十次以上.
当然,这里的希望是来自PayPal技术团队的人回复.
我不能等待另一个小时,我不能.