views:

105

answers:

1

I am developing web application using MVC.

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

I know I can reuse the modal in winforms.

But can I reuse the controller in winforms

+1  A: 

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.

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.

A better solution would be to abstract out 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.

That's my 2¢ on the subject anyway.

Chuck
+1. For good explanation. As you rightly said the controller is having very less code. But the thing is I still some how want to use it.
Sachin