我可以共享控制器的ASP.Net MVC与WinForms应用程序和如何? [英] Can I share controller of ASP.Net MVC with WinForms Application and how?

查看:178
本文介绍了我可以共享控制器的ASP.Net MVC与WinForms应用程序和如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVC开发网络应用程序。

I am developing web application using MVC.

设计模型和控制器有很多努力。

A lot of efforts are going into the design model and controller.

我知道我可以在winforms中重用模态。

I know I can reuse the modal in winforms.

但是我可以在winforms中重用控制器

But can I reuse the controller in winforms

推荐答案

如果我正确地读取并且你想在WinForms应用程序中使用你的控制器,答案是,虽然(几乎任何东西)在技术上可能,会想。

If I am reading this correctly and you want to use your controller in a WinForms application, the answer would be that while (like almost anything) it is technically possible it is not likely you would ever want to.

最大的问题是,使控制器有用的ASP.NET MVC的功能在控制器周围的框架中实现。这些功能支持视图,过滤器和控制器之间的信息流(仅举几例),并且不在不同组件之间显式传递。为了利用所有这些功能,你需要适应MVC框架或编写自己来处理像ViewData和绑定和...没有,只是没有。也许如果你的控制器足够简单...我在说什么?只是不要这样做。

The biggest problem is that the features of ASP.NET MVC that make the controllers useful are implemented in the framework around the controllers. These features enable the flow of information between the views, filters and controllers (to name a few) and are not explicitly passed between the different components. In order to take advantage of all those features, you would need to adapt the MVC framework or write your own to handle things like ViewData and binding and... no, just no. Maybe if your controllers were simple enough... what am I saying? Just don't do it.

一个更好的解决方案是重构将被重用到业务层或其他常见程序集的逻辑,并将其包含在的项目。如果你的控制器写的很好,没有那么多的代码,他们开始,所以你不会通过重用它们节省很多。我了解到,从这本书开始,并在遵循几个项目的建议后,它。基本原因是,您的控制器应该用于控制应用程序的流量以及UI和其余应用程序之间的数据。他们不应该包含复杂的商业逻辑。

A better solution would be to refactor the logic that is going to be reused into a business layer or other common assembly and include that in both of your projects. If your controllers are written well, there's not that much code in them to begin with so you're not saving much by reusing them. I learned that from this book and after following its advice on a couple of projects have come to agree with it. The basic reasoning is that your controllers are supposed to be used to control the flow of the application and the data between the UI and the rest of your application. They are not supposed to contain intricate business logic.

这是我的2¢的主题。

这篇关于我可以共享控制器的ASP.Net MVC与WinForms应用程序和如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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