views:

93

answers:

2

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 serveral 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 frontend 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.

A: 

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.

Scott
which I think is I unserstood it right the Controller should contain the BusinessLogic (not an additional BLL), but the controllers end with a "retun View();" which calls a Webfront, may I make this configurable to call a "WPF"-View or "Win32"-View, using a Specific MVC Pattern for each kind of View isn't a good mode because in that case I'd have to rewrite my Controllers 3 times.In practice I want to Views at the same time, one Webbased and another for a Desktop PC, which will be compiled into a .exe, But I wish only one Controller.
john84
@Johannes, Controllers are not the BLL, Controllers are just HTTP Request mappers/managers/supervisors. MVC is really not suited to state-full winform or wpf applications, can be done but MVP or MVVM are better patterns for that type of development.
jfar
@jfar, well in that case my interpretation to use MVC for all Webspecific logic and an additonal BusinessLogic for all generic Logic which should be reused in a WPF App is right?
john84
@Johannes, I think your on the right track now. Keep MVC web only.
jfar
tho' i would add. the M (in MVC) can be a BLL model that is in a self contained core dll which CAN be referenced by multiple clients - if you want.
jim
+4  A: 

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.

Jeff Sternal