What should keep into this design approach

空扰寡人 提交于 2019-12-25 05:50:16

问题


My Project solution is as below:

  1. MVC Project (Containing reference of both projects listed below)
  2. WCF Service containing business methods (Containg reference of below listed project)
  3. Common Project for DTO or BusinessOBject

IN MVC - Calling the WCF service method is as follow - IList<Employee> RetriveData() it is called from MVC - ServiceClient.RetrieveData() , now problem is return object Employee point to ServiceHost.Employee object instead of - Common.DTO.Employee object (Library project) so, it gives type casting error.

Can any one suggest me what is the solution over here or i should remove "Common.DTO" project refernece from MVC and only use Servicehost.Employee object.

Please guide me on this design, what should use.

NOTE: all objects are DATACONTRACT (serilizable). In MVC applicaiton, after retrieing DTO object, i do convert them into Viewmodel (It also internally refer any collection object like IList<ServiceHost.LookupItem> . Does it ok to use all generated serilized object directly OR , do i have to convert/cast each return object into common.DTO. object and then convert into ViewModel ?

Thank You


回答1:


Don't use Visual Studio's Add Service Reference. Doing so will result in multiple types being defined in the solution and client-proxies that over time will become out of sync.

It is much better to define a common contracts assembly that your whole solution uses.

Please see WCF the Manual Way…the Right Way specifically page 3

You should try to follow patterns such as canonical data model whenever possible. This means the same type for POCO ORM; WCF; and as aggregates in your view model. Data conversion is expensive; leads to increased maintenance and possible fidelity loss. http://www.soapatterns.org/ http://www.eaipatterns.com/




回答2:


This really depends on what level of abstraction you want.

If ServiceHost.Employee is your domain model and MVC is your presentation layer then it would make sense to use a DTO to bridge the gap here. Given that's the approach you seem to want to use then the solution would be to have ServiceClient.RetrieveData return IList<Common.DTO.Employee> instead of IList<ServiceHost.Employee>.



来源:https://stackoverflow.com/questions/24323112/what-should-keep-into-this-design-approach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!