Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should MVC Controller be in separate DLL?

I've created a .NET winforms MVC. The Controller and View are in the same EXE. Model is in a set of DLLs that get used by several groups. The MVC is very explicit. Model knows nothing of Controller and Controller knows nothing of View. I'm thinking to put the Controller in its own DLL so that it can be unit tested. Highly unlike someone will reuse the controller. Unit testing is the only reason I have for the move into a DLL.

Conceptually, should the controller always be in the same assembly as the View? What are reasons for/against keeping them together?

like image 756
4thSpace Avatar asked Jan 23 '09 19:01

4thSpace


People also ask

Can we have two controllers with same name in MVC?

One should be of type Controller, and the other ApiController, then they can both exist with the same name.

What should controller do in MVC?

A controller is responsible for controlling the way that a user interacts with an MVC application. A controller contains the flow control logic for an ASP.NET MVC application. A controller determines what response to send back to a user when a user makes a browser request.

Can MVC have multiple controllers?

In Spring MVC, we can create multiple controllers at a time. It is required to map each controller class with @Controller annotation.

Should you split your ASP.NET MVC project into multiple projects?

It shouldn't! That's why it's designed in a modular way. In most web applications out there, we version and deploy all these assemblies (Web, BLL and DAL) together. So, separating a project into 3 projects does not add any values.


1 Answers

Separation of controllers and views are an abstract concept. There's no strict rule that you should physically keep them separate (just like tiers in a three-tier application). However there might be some advantages in either approach.

Separating assemblies has the following benefits:

  • Reduces the possibility to accidentally couple views to controllers and breaking the separation.
  • Makes it easier to edit views without recompiling controllers at all (which is great from a deployment perspective).
  • Building views and controllers become separated, so you can test the one of them even if the other does not build at all.

However, it might be unfeasible for small projects. For very small projects you might want to ship a single executable and nothing else along it. Also, you might not want to create 3 separate projects.

Hey, you might not wanna unit test it at all ;) Ouch, my head is hurt, where did this big brick come from? :))

like image 70
mmx Avatar answered Sep 27 '22 20:09

mmx