简体   繁体   English

在所有解决方案项目中共享域模型对象

[英]Sharing Domain model objects in all solution projects

I have all the time the same situation when building my projects . 在构建我的项目时,我一直都有相同的情况。 I have the main Domain model (entity framework model) . 我有主要的域模型(实体框架模型)。 I added a wcf data service project to help query this model . 我添加了一个wcf数据服务项目来帮助查询此模型。 Now if I want to use one of the objects of the model either I have to reference the Domain model dll and this is not always good because the project maybe will be silverlight , or I can use a service reference and this maybe better choise but not clear poco object. 现在,如果我想使用模型的其中一个对象,我必须引用Domain模型dll并且这并不总是好的,因为项目可能是silverlight,或者我可以使用服务引用,这可能更好的选择但不是清除poco对象。

Do you have any suggestion to best practise how I can share common model , so I can use it with the UI , remote services ... 你有什么建议可以最好地练习如何分享通用模型,所以我可以将它与UI,远程服务一起使用......

Thanks in advance ... 提前致谢 ...

Well your domain model should be POCO's, not EF model's. 那么你的领域模型应该是POCO,而不是EF模型。

If you use pure POCO's, then your domain model project will not reference EF at all, it's a basic .NET class library which can be consumed by any .NET client. 如果您使用纯POCO,那么您的域模型项目根本不会引用EF,它是一个基本的.NET类库,任何.NET客户端都可以使用它。

Either use POCO's, or create a facade between the EF model and your clients, where you can project the EF entities into DTO's. 要么使用POCO,要么在EF模型和客户之间创建一个外观,您可以在其中将EF实体投影到DTO中。

What do you mean by domain model? 域名模型是什么意思? Do you mean just classes generated by EF or T4 template? 你的意思是EF或T4模板生成的类吗? Or do you mean real domain objects where generated classes are combined with another partial class containing real business methods? 或者你的意思是真正的域对象,其中生成的类与包含实际业务方法的另一个部分类组合?

In the former case you can simply share assembly with client. 在前一种情况下,您可以简单地与客户共享汇编。 In case of service it will create tight coupling between service and client which is usually considered as a bad practice. 在服务的情况下,它将在服务和客户之间产生紧密耦合,这通常被认为是一种不好的做法。 But still there are scenarios where WCF is used instead of remoting and in such case sharing assembly is common scenario. 但仍然存在使用WCF而不是远程处理的情况,在这种情况下,共享程序集是常见的情况。

In the latter case the point is: DO NOT SHARE domain objects with clients of your services. 在后一种情况下,重点是: 不要与服务的客户端共享域对象。 Domain objects and their methods are for service, not for client. 域对象及其方法用于服务,而不是客户端。 Use specialized DTOs or objects created from service reference. 使用从服务引用创建的专用DTO或对象。

If you work with web services you should follow simple rule: your model doesn't cross physical boundary. 如果您使用Web服务,则应遵循简单的规则:您的模型不会跨越物理边界。 It means that model is internal to the service and client doesn't use it. 这意味着模型是服务的内部,客户端不使用它。

It's probably not a great idea. 这可能不是一个好主意。 But I've heard EF4 has POCO support, so you can just have them in separate assembly referenced by anyone. 但是我听说EF4有POCO支持,所以你可以将它们放在任何人引用的单独程序集中。

For Silverlight in particular, have a look at wcf ria services . 特别是对于Silverlight,请看一下wcf ria服务

Some suggestions on how to handle sharing a domain model across solutions, when at least one is a Silverlight solution, can be found at the following link: 有关如何处理跨解决方案共享域模型的一些建议(至少有一个是Silverlight解决方案)可以在以下链接中找到:

Best practice for shared Silverlight and .NET 3.5 code? 共享Silverlight和.NET 3.5代码的最佳实践?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM