简体   繁体   中英

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 . 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.

Do you have any suggestion to best practise how I can share common model , so I can use it with the UI , remote services ...

Thanks in advance ...

Well your domain model should be POCO's, not EF model's.

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.

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.

What do you mean by domain model? Do you mean just classes generated by EF or T4 template? 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.

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.

If you work with web services you should follow simple rule: your model doesn't cross physical boundary. 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.

For Silverlight in particular, have a look at wcf ria services .

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:

Best practice for shared Silverlight and .NET 3.5 code?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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