What are advantages & disadvantages of creating multiple controllers in single project using asp.net mvc2 [closed]

StackOverflow https://stackoverflow.com/questions/19947995

  •  30-07-2022
  •  | 
  •  

Question

I am creating a asp.net mvc2 project which contains multiple modules in the project.I am thinking to create supprate controller for each module, but i want to know what are the advantages & disadvantages out of it?

Was it helpful?

Solution

Seperate controllers means a Seperation of Concerns, you would have separate controllers to handle logic that should be separated. So you won't get a cluttered controller handling everything in your application. Besides clarity in your application, this brings the benefit that if you need to change one thing, you don't break other code handling other logic in the same place.

Naturally this separation is also present in your Views folder, so you'd have clear oversight what's going on where in your app.

Also, if you have a lot of dependencies that your one controller needs (like services getting different domain models) you would have these listed in one place, which would make it less clear what the primarily function of that controller is. It's nicer to have more controllers with less dependencies each.

Another benefit is that you get user friendly Urls without much effort:

www.domain.com\home\index

Pretty much spells out this is the homepage.

And:

www.domain.com\account\login

does so too.

Basically, make objects (controllers) for each "section" of your web app, like you would make objects for each functionality of the business logic.

OTHER TIPS

i would read this article: Biggest advantage to using ASP.Net MVC vs web forms

since it already covered your question for a big part.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top