views:

85

answers:

3

I'm writing a WinForms application and want to have an "MVC-Type" Design. Actually it's more MVP or MVVM,.

The plan is to have a Central Controller which does all the actual work, so that the Forms just render out ViewModels and handle user input, but everything that actually does something goes through the Controller.

I just wonder if this is a good idea, and where to put the Controller? The current idea is to have a static class which is initialized in Program.cs (Sending in some Dependencies like IMyDatabaseRepository) so that it just stays a controller that delegates work between User Interface and Model.

As you might guess, I come from a Web Background and have little experience with WinForms architecture. Previously, my MainForm was the Controller class, holding all the State Variables, which obviously means that my MainForm is my application rather than just a part of the User Interface.

+2  A: 

Nice question Michael!

Here are some links:

Hope these help you to structure your project properly!

TheVillageIdiot
Those links do not appear to be working.
Ty
http://sachabarber.net/?p=515http://www.codeproject.com/KB/WPF/BeginWPF1.aspxI believe those are the first two and they do look pretty good.
Ty
Fixed the layout, looking at them right now.
Michael Stum
Michael, how did you find the last one? All it said was "Nice article on this wordpress blog".
Ty
I've edited his article (2000+ Reputation Feature), the links were in there, but because he used HTML Tags they did not get rendered. Thanks by the way, even though I am doing classic WinForms, those WPF Architecture artciles still look very useful.
Michael Stum
thanks @Michael for editing links. I'd noticed the color of links but thought I've visited the pages so they are appearing so :)
TheVillageIdiot
Accepting this because after looking through this and some other sources, I've decided to move from WinForms to WPF for this App - the whole ICommand and MVVM stuff looks promising.
Michael Stum
A: 

I don't know if this is a better way, but I am having Structuremap create my controller and database instance.
The main form has no real code in it - it just loads the first set of controls and then starts the controller. The user controls on the form use StructureMap to access the controller.
My project is regular WinForms and not WPF and is my first time using the MVC pattern with WinForms.

Maggie
A: 

You might have a look at the WAF Windows Forms Adapter download. It comes with the BookLibrary sample application which uses a Controller / MVVM design together with Windows Forms.

jbe