Is ASP.NET MVC a real MVC-Pattern?

2019-07-16 05:50发布

For the last couple of Days I have been working on a small web application. I decided to use ASP.NET MVC. I made this decision mostly because I think it is the best way to really control the web front-end and render valid HTML pages. However, I know that MVC can be much more.

Even though my App is quite small, I am focusing on my application's architecture. It is important to me to have several layers, two of which should be switchable at any time: the user interface (Web / Desktop / Webservices) and the data access logic (to support several databases). I thought that in a Model View Controller pattern this would be possible.

In this case will it be possible to replace my web based front-end with a Win32 or WPF front end? Is this possible or did I understand something wrong? I couldn't find a way to do this.

The only way I found to do this is to create an MVC-Layer, BusinessLogic-Layer, BusinessObject-Layer and a DataAccess-Layer. In that case all generic stuff which can be reused by a WPF App for example I put into the business layer, all the MVC specific Stuff I put in the MVC-Layer, and most what my Controller does is calling BL Methods and building a ViewModel and returning it to the view. I am not sure if this is a correct interpretation and would be thankful for suggestions about better practices.

2条回答
Emotional °昔
2楼-- · 2019-07-16 05:59

Yes, it employs a real MVC pattern, in at least the sense specified by Martin Fowler's Patterns of Enterprise Application Architecture (perhaps the closest thing we have to a canonical definition - see his article 'GUI Architectures' for an extended discussion).

At its heart, MVC is about establishing a clear separation of concerns for user-interface-driven applications.

MVC does not purport to make it easy to switch between stateless interfaces (like web applications) and thick client applications (like WPF or WinForms). Those platforms have different strengths and weaknesses: trying to use a single controller to satisfy both would lead to a sub-par lowest-common-denominator implementation.

查看更多
我想做一个坏孩纸
3楼-- · 2019-07-16 06:16

I dont really understand your question. If you want views that aren't in HTML, look at different ASP.NET MVC View engines. If you want something to give you a WinForms view, you'll have to code the business logic the same way, but then grab all these classes/data from a WinForms app in your same solution, and when the user wants to go to this "page", they will have to download the WinForms app and run it. You can try to make it look like web stuff but that's not guaranteed.

查看更多
登录 后发表回答