locked
Can I create separate projects for model view and controller in mvc? RRS feed

  • Question

  • I want to know that can I create separate web application projects for each model, view and controller (3 projects - model in one project, view in another project...)? Should I keep them in one project?

    Thanks in advance.

    Tuesday, August 9, 2011 11:03 AM

All replies

  • Hi,

    Doing something like that boils down to how the compiled assemblies are deployed and well shared really. Is there a point to splitting them into different projects?

    will the views support other models seperate from the solution and so can be shared? can the controllers generic enough to control models and views that aren't part of the solution? Another way to ask that is can the controllers assembly be taken out of your solution and dropped into a seperate project?

    or is there cause for your solution to deplay models closerl to the database server machine while the controllers and views sit on a web server in a less restricted area of the network?

    These are really the questions that you as when splitting up a project and especially a web project; where there is more than one computer involved.

     

    Honestly, without knowing more, I'd say this isn't a good way to split up your project into assemblies. I'd be more inclined to split on behaviour; group things that are needed to perform similar functionality. Example; if there was a Paypal integration then I'd take the models, views and controllers and all the supporting code out and put it in a seperate DLL, then I'd say perhaps all the Shipping stuff together is one DLL, and then maybe all the User management stuff... difficult to say because it depends on what the project will do.

    But you will see that already each is more usable in your and other applications. They can be secured independently, they can be versioned and tested as a unit independently and together in integration.


    "The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination." - Fred Brooks
    Tuesday, August 9, 2011 2:49 PM
  • Hi

    I suggest Model in seperate layer.

    It is better to keep these , views and controller, are also in seperate layers. And it depends on size of the project.

    Check with this more discussions on this topic

    http://devlicio.us/blogs/billy_mccafferty/archive/2009/01/09/an-argument-for-moving-asp-net-mvc-controllers-to-a-separate-assembly.aspx

    Hope this helps you..


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    Tuesday, August 9, 2011 2:54 PM
  • That was a good discussion in that link, Billy McCafferty makes some good points.  However I don't think that many of the problems he cited in his example would be solved simply by putting the controller into a separate assembly (although I don't oppose to doing this).  The real reason there were problems in his example was that they weren't using a good repository pattern to enforce IoC principles.  Even with the controller in another assembly they could still manage to have it too tightly coupled to the Model unless they create proper repository classes. So I don't think putting the controller it's own class library would solve the problem by default.  It would however make the developers more aware of the separations of the 3 main isolations in the SOC pattern which is a good thing.
    Tom Overton
    Friday, August 12, 2011 6:54 PM