Model View Presenter with both WebForms and WinForms

 
89   96.5
Mar 29, 2012
 
I have started a new project that requires both WinForms and WebForms UI.  I chose to use the model view presenter pattern for the WinForms UI and would like to use the same presenter and models with the WebForms UI.

However, I have found some areas that are difficult to abstract away from the UI technology into the presenter or model.  For example, we already have existing tables for users and roles and therefore have built custom login/user validation classes in the business layer which are then used in the model for the WinForms solution.  For the WebForms solution I have implemented customer membership providers so that I can make use of the membership login controls.  I would like to have the presenters and models shared between the WebForms and WinForms solutions, however to do this I would need to move the custom membership providers in to the model therefore creating a direct dependency on System.Web.Security.

One solution would be to leave the custom providers in the web project and have them implement a custom interface defined in the model and then pass the dependency in to the model.  However, as my custom membership provider has a dependency on my business layer I would have to have a reference from the web project to the business layer which is bypassing the model.  So either way dependencies are leaking in to areas they shouldn't.

Is it realistic in practice to be able to use the MVP pattern with multiple UI technologies?  Or is it likely to cause more issues and would it be best to implement the pattern separately for both so essentially having 6 projects (WebForms.UI, WebForms.Models, WebForms.Presenters, WebForms.Views and WinForms.UI, WinForms.Models, WinForms.Presenters, WinForms.Views).

Initially there won't be much crossover of functionality as the WebForms solution is for the client and the WinForms solution is for the backend processing features so implementing MVP separately for both may not be too much of an issue, although this may change in the future so that some functionality is available in both which depending on the exact implementation of the views may result in duplication of code.



1,364   100.0
Mar 30, 2012
MVP works great with multiple UI.  I do have some experience earlier on having an application both working on Windows and ASP.NET webforms and MVP was very handy to make this port without much pain.  Though we had to put in lot of abstractions, but the end result was very satisfying.

Its another story that we are rebuilding the app on ASP.NET MVC (not due to any constraints with MVP) but due to the fact that we are moving towards one UI technology across all our apps.

But MVP did definitely helped us and also we did have some unit test which made the transition much smoother.  Overall, you wont' regret having this pattern in place.

So, in a nutshell, if you are planning multiple UI, then its better to stick with MVP and you can easily scale to other UI like mobile, tablet etc.. without much work (if need be).

For the authentication we specifically created custom principal object which is used by both web and windows app.  Yes we didn't use membership provider because we already had our own custom authentication system in place which played nicely with both technology.

You can provide a common abstraction for security over membership provider and use it in multiple place..

All the very best with your endeavor..