Search This Blog

Saturday, November 30, 2013

Front Controller Vs Page Controller in .Net


 


Criteria

Page Controller

 
Front Controller
 
Where to use
ASP.NET Web forms are implemented based on the page controller patter
ASP.NET MVC uses front controller pattern
Page Controller architecture has separate entry points for each request
Front controller architecture has a single entry point for all requests
Complexity / Ease of Implementation
Low complexity. Suits simpler web applications. Most of the time the commercial web application frameworks have built-in support.
Complexity is high compared to page controller. The single controller itself can be complex. However many CMS frameworks have this built in. (Eg: DNN)
Code Duplication / Code quality
Duplication can be high as the application grows. Has to implement a BaseController from which all page controllers extend.
Low code duplication. All common tasks can be put inside the front controller
Testability
Can be low. Has to go for a 2 part controller where one is HTTP dependant and the other is independent and testable.
The front controller will only handle transfer of the request to independent commands which could be testable. Has to be careful
Adaptability/Flexibility
When the page of the web application is very different from each other, the code duplication can be higher. If you try to counter this with separate inheritance tree, it can grow complex soon.
Since the front controller is centralized it's highly configurable. That's why many CMS frameworks use front controller to increase flexibility.
Performance
No extra bottleneck if plain page controller is used. However if a deep inheritance hierarchy is used performance can be a bit lower than normal.
The single front controller can end up being a bottleneck since it answers to all requests. Should avoid doing I/O or DB calls in the front controller as much as possible.
Thread Safety
The same page controller instance might handle (Depending on the web application framework, eg: ASP.Net) requests for the same page and thread-safety has to be considered. Use of static instances might be problematic.
Front controller can instantiate new command objects for each request and ensure thread safety at controller level. However model code still has to be thread safe.
Work distribution and responsibility
Easier to distribute the work among developers since each area of work can be done completely separately
Each developer has to have a good understanding of the Front Controller behavior as everything depends on it.

 
Post a Comment

Popular Posts