简体   繁体   English

通过Windows和Web UI在C#应用程序之间共享演示逻辑

[英]Sharing presentation logic between C# application with windows and web UIs

I need to build an application in C# that will have multiple UIs, 2 for web and one that will be the same application, but able to be used with no internet access. 我需要使用C#构建一个具有多个UI的应用程序,其中2个用于Web,另一个将是相同的应用程序,但不能在没有Internet访问的情况下使用。 I am leaning towards MVC for web, then MVVM/WPF for the windows application (Silverlight is not an option). 我倾向于将MVC用于Web,然后将MVVM / WPF用于Windows应用程序(不能选择Silverlight)。 I should be able to inject a different repository implementation for the two paradigms, thus solving the disconnected-from-the-internet issue. 我应该能够为这两种范例注入不同的存储库实现,从而解决与互联网断开连接的问题。

What I am wondering is how best to re-use as much presentation logic as possible. 我想知道的是如何最好地重用尽可能多的表示逻辑。 Ideally, I would like to be able to use the same controller/presenter-type entities to run both UIs. 理想情况下,我希望能够使用相同的控制器/演示者类型的实体来运行两个UI。 I'm looking for an example of a good solution to this problem. 我正在寻找解决此问题的一个好例子。 I don't see a clear path to re-using MVC's Controllers (they seem too tighly bound to the MVC framework to work), but at the same time I'm not excited about the overhead involved in implementing a custom MVVM or MVP pattern for the web (which I fear is the answer). 我看不到重用MVC控制器的明确途径(它们似乎太紧密地绑定到MVC框架而无法工作),但是与此同时,我对实现自定义MVVM或MVP模式所涉及的开销并不感到兴奋网络(我担心这是答案)。

Alternatively, am I crazy to even try to re-use those components? 另外,我是否疯狂甚至尝试重用那些组件? Is it not worth the hassle? 这不值得麻烦吗? We can easily share the services underpinning the UIs, but it seems a shame to write such similar UI code twice. 我们可以轻松地共享作为UI基础的服务,但是两次编写类似的UI代码似乎很可惜。

The right thing to do is to share only the Business Layer and Database Access Layer . 正确的做法是仅共享业务层数据库访问层 At least you will have consistency between all the clients. 至少您将在所有客户端之间保持一致。

Then build the clients taking advantage of the benefits of each platform (richness of the desktop app and simplicity in the web app) 然后利用每个平台的优势(桌面应用程序的丰富性和Web应用程序的简单性)来构建客户

Of course it all depends on the budget. 当然,这完全取决于预算。

You have the option of using WPF for everything for max re-use. 您可以选择对所有内容都使用WPF,以实现最大程度的重用。 WPF can be deployed as partial trust XBAPs. WPF可以部署为部分信任XBAP。

There are downsides though * Download size can be a problem * Clients need the correct framework version and can only run in Internet Explorer (Firefox through plugin (not working on Windows 7)) 尽管存在一些缺点*下载大小可能是一个问题*客户端需要正确的框架版本,并且只能在Internet Explorer中运行(Firefox通过插件运行(不适用于Windows 7))

I've tried it on a solution with a small XBAP client and a larger Standalone Application - and it is really minor details that cannot be reused (Window in app, Page in XBAP and so on). 我已经在具有小型XBAP客户端和较大的独立应用程序的解决方案上进行了尝试-实际上这是细微的细节,无法重用(应用程序中的窗口,XBAP中的Page等)。 Makes for nice consistent layout too. 也使布局保持一致。

This is slightly hackish (and not really recommended, unless you really understand what you are doing :)), but you could try creating a desktop app, which embeds a browser. 这有点骇人听闻(除非您真的了解自己在做什么,否则不建议这样做),但是您可以尝试创建一个嵌入浏览器的桌面应用程序。 This enables you to reuse the GUI. 这使您可以重用GUI。 You will also need to package a web-server, which might be a problem though if you are using C#/MVC/.NET. 您还需要打包Web服务器,但是如果使用的是C#/ MVC / .NET,则可能会出现问题。

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

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