它是重复使用WPF的ViewModels MVC中是否可行? [英] Is it feasible to reuse WPF ViewModels in MVC?

查看:123
本文介绍了它是重复使用WPF的ViewModels MVC中是否可行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须写在WPF / WCF富客户端应用程序,并正打算创建在ASP.net一个同伴网站(使用MVC如果可能的话)。

we have a rich client application written in WPF/WCF and are intending to create a companion website in ASP.net (using MVC if possible).

我被要求找出多少我们目前的codeBase类,我们可以重复使用(由一个独立的团队) - 和我没有什么与ASP.net没有经验

I've been asked to figure out how much of our current codebase, we can reuse (by a separate team) - and I have little to no experience with ASP.net.

我们将重新使用我们的域模型,但没有任何点分离出我们的ViewModels的具体WPF零部件和重用MVC中WPF无关的部分?它甚至遵循同样的范式?我们使用RelayCommands专为统领,所以这将是容易将保鲜膜中的一些具体ASP.net所包含的方法......但如何对UI特有的东西 - 例如确实ASP.net使用INotifyPropertyChanged的 - 或者它是如何处理的UI更新

We will reuse our domain model, but is there any point in separating out the WPF-specific parts of our ViewModels and reuse the WPF-agnostic parts in MVC? Does it even follow the same paradigms? We use RelayCommands exclusively for commanding, so it would be easy to wrap the contained methods in something ASP.net specific... But how about UI-specific things - e.g. does ASP.net use INotifyPropertyChanged - or how does it handle UI-updates?

推荐答案

对于我来说就没有任何意义。您的模型应该包含所有重要的业务逻辑code,应该是最大的可重用性的地步。您的视图模型应该只包含presentation逻辑,因为这是为桌面和Web应用程序等不同,它没有任何意义重用这些。

For me it wouldn't make any sense. Your models should contain all of your important business logic code and should be the point of greatest reuseability. Your view models should contain presentation logic only, and as this is so different for a desktop and web app, it doesn't make sense to reuse these.

MVC不使用UI更新任何约束机制,为Web应用程序本质上是无状态的。你实际上将最有可能最终使用视图模型为你的MVC应用程序,但在这些MVC行事用于渲染的每个HTTP请求提供数据的意见简单的数据传输对象(DTO的)。一旦视图显示,你需要回到服务器更新视图模型和重新呈现视图。

MVC does not use any binding mechanism for UI updates, as web apps are stateless by nature. You will actually most likely end up using view models for your MVC app, but in MVC these act as simple data transfer objects (DTOs) for providing data to the views for rendering for each HTTP request. Once the view is rendered, you would need to go back to the server to update the view model and rerender the view.

另外,你当然可以用更新的脚本UI客户端。 Knockout.js 是一个不错的JS库客户端视图模型/视图结合。

Alternatively, you can of course update the UI client side with scripting. Knockout.js is a nice JS library for client side view model/view binding.

这篇关于它是重复使用WPF的ViewModels MVC中是否可行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆