我能否避免重复我的业务层? (。净)我的、业务

2023-09-03 07:10:27 作者:我年轻丶心不定

我有一个高科技演示应用程序编写,与多个客户端: Web客户端(ASP MVC 3),桌面客户端(目前这将是一个WCF应用程序,规划香料它麦德龙更高版本)和移动客户端(WP7是默认的任务,但如果我觉得自己像一个时间百万富翁,我可能会尝试MonoDroid太)

I have a tech demo application to write, with multiple clients: web client (ASP MVC 3), desktop client (currently it'll be a WCF app, planning to spice it up to Metro later) and a mobile client (Wp7 is the default task, but if I feel like a time-millionaire, I might try MonoDroid too)

我使用WCF为客户思考。 我用EF模型优先用于后端思考。 然而,当我试着找出我在哪里把我的域逻辑(验证,计算性能等),而无需手动复制一切,我已经在我的EF模型宣布我的问题就出现了。

I was thinking using WCF for the clients. I was thinking using EF Model First for back-end. However my problem arises when I try to figure out where do I put my domain logic (validation, computed properties, etc) without having to manually duplicate everything I already declared in my EF Model.

我的第一个主要问题是,英孚已经跟踪内置的( obj.Components.Add(...); db.Save(); )一个不错的对象,但此功能不可用在客户方轻松。有没有办法解决它,而无需实现自己的? (我知道该怎么做,但这是太多的工作,为这个演示)

My first main problem is that EF has a nice object tracking built in (obj.Components.Add(...); db.Save();), but this functionality isn't available on the clientside easily. Is there a way around it without having to implement my own? (I know how to do that, but that's way too much work for this demo)

我的第二个主要问题(如标题暗示)的域逻辑,主要是验证。

My second main problem (as the title suggest) is the domain logic, mainly validations.

如果我重新编译的业务对象,以客户方和WCF序列化到相同的对象? 我应该尝试与客户端的WCF生成的类工作? (回第一问题)

我应该尝试使用共享的组件? Should I recompile the business objects to clientside and serialize the wcf into the same objects? Should I try to work with the WCF generated classes on client-side? (back to the first problem)

Should I try to use shared assemblies?

如果我写我的逻辑到MVC控制器,我的WCF服务将无法整齐地打电话给他们。

If I write my logic into MVC controllers, my WCF service won't be able to call them neatly.

有没有在客户端使用相同的验证一个很好的方式?

Is there a nice way to use these same validations on client side?

我应该报废了整个事情,并尝试RIA服务?

Should I scrap the whole thing and try RIA services?

呵呵,这么多的问题...

Oh, so many questions...

推荐答案

我已经建立了跨平台的应用程序之前,在Windows上(特别是WPF / Silverlight客户端,C#的SQL Server后端)和我所做的事情是这样的。

I've built cross-platform apps before on Windows (specifically WPF / Silverlight clients, C# SQL Server back end) and what I've done is this.

在使用的消息层或中间件(RabbitMQ的异步消息,或web服务的请求/响应)和序列化技术(Protobuffers或JSON),其在全部三个边界的工作。使用跨平台中间件在可能的情况。这就是为什么我提到的RabbitMQ / protobuffers / JSON。 感动了所有的业务逻辑的服务器 - 在所有客户端不能访问数据库,并要经过中间件。客户端,包括台式机,成为名副其实的就像薄的浏览器访问的所有操作中间件服务。 创建共享组件,以保持客户端(S)和服务器之间的消息,datacontracts和普通类可以由所有客户端和服务器被引用。

这最后一步(共享组件)涉及创建1个项目是完整的C#兼容(所以适用于WPF台式机或服务器)和附加项目为每个Web客户端(Silverlight中,WP7)。要在多个客户端双部署code你有源在桌面assemblie一个副本,然后在添加为链接相同的源文件的Silverlight / WP7组件。你必须有一些#如果preprocessor报表,但大体上可以以code。使用这种方法的双部署大块。

This last step (shared assemblies) involves creating 1 project which is full C# compatible (so works on WPF Desktop or Server) and additional projects for each web client (Silverlight, WP7). To dual deploy code on multiple clients you have one copy of the source in the desktop assemblie and then "Add as Link" the same source files to Silverlight / WP7 assemblies. You will have to have a few #if preprocessor statements but by and large it is possible to dual deploy large chunks of code using this method.

您堆栈变为

客户端:

所有客户都有系列化,Web服务/中间件和MVVM / MVC模式的客户端实现

all clients have serialization, client side implementations of webservices/middleware and MVVM / MVC patterns

中间件:

中间件服务器/ WPF桌面上实现可以是相同的。 WP7和monodroid等将需要是不同

middleware implemetation on server / wpf desktop can be the same. Wp7 and monodroid etc will need to be different

信息/ DataContracts:

Messages/DataContracts:

使用我上文所述

服务器:

所有的业务逻辑,数据库访问和服务器端中间件的实现。对于数据库访问,我用PetaPoco作为一个优秀的MicroORM。我相信microORM实现权力堆栈溢出,但我可能是错误的。

All business logic, DB access and server-side middleware implementations. For DB Access I've used PetaPoco as an excellent MicroORM. I believe a microORM implementation powers stack overflow but I might be mistaken.

我也想看看本文的灵感。这是可能的 - 我已经写了客户机/服务器应用程序与SL / WPF客户端和C#的服务器,使用上述方法还WPF客户端/服务器的Java。

I would also take a look at this article for inspiration. It is possible - I've written client/server apps with SL/WPF clients and C# servers, also WPF client/Java servers using the above methods.

最好的问候,