I have been trying to find the different between MVC and 3-tier architecture in ASP.NET. I referred to some previous some previous questions and some pages, but could find a clear answer.<br/>
Here is a a msdn page about MVC implementation: http://msdn.microsoft.com/en-us/library/ff647462.aspx
Consider, I ahve this code: Single page aspx UI and code as well
using System;
using System.Data;
using System.Data.SqlClient;
public class Solution : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
String selectCmd = "select * from Recording";
SqlConnection myConnection =
new SqlConnection(
"server=(local);database=recordings;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Recording");
recordingSelect.DataSource = ds;
recordingSelect.DataTextField = "title";
recordingSelect.DataValueField = "id";
recordingSelect.DataBind();
}
}
1. Seeing the above
msdn page link for the Controller class, I am not able to discern the difference between the business logic (that would have been similar for a middle tier in a 3 tier architecture) and the controller.<br/>
2. Is 3-tier and MVC completely different thing? Are the ASP.NET application in Visual Studio already separated file as in MVC form? If these are not different, which one is the preferred style?<br/> 3. What's the MVC framework about then if the .aspx and .aspx.cs are already spearated?
MVC falls under architectural pattern and is primarily concerned with UI and interaction logic separation. The other layers of the 3 tier will still be applicable.
The most common MVC frameworks usually follow a Front Controller pattern. i.e. rather than request getting landed to a specific page, the request is routed to a common front controller, whose sole responsibility is to invoke the specific requested controller
based on information passed in the querystring or as part of the request.
Ideally the controller should be as thin as possible and its sole responsibility should be to infer the request and call appropriate business or data access service. There shouldn't be any business specific logic in the controller.
My recommendation is to look at the ASP.NET MVC implementation for more information as this is built on the industry adopted best practices...
I blog at http://rajeshpillai.net and have a community startup http://ownabook.org/
(Don't forget to click "Mark as Answer" on the post(s) that helped you.)
YOur Model is the right place to start with Business logic. you can write your Business logic in WCF service and use it in Model. Youcan writ4e youe BL in Seprate Assembly.
ther places you don't write youe business logic or you avide them are:
View, View Model, controller.
Controller should not have heafty coding, Controller should pass the incomming values from View to Model and let' model work on incomming request.
"Mark as answered if you feel this helps you"
"There are NO shortcuts for success, better stop taking one."
harpreet31
Member
39 Points
101 Posts
Difference between MVC controller and business logic (3 tier)
Mar 17, 2012 11:25 AM|LINK
I have been trying to find the different between MVC and 3-tier architecture in ASP.NET. I referred to some previous some previous questions and some pages, but could find a clear answer.<br/>
Here is a a msdn page about MVC implementation: http://msdn.microsoft.com/en-us/library/ff647462.aspx
Consider, I ahve this code:
Single page aspx UI and code as well
<%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <html> <head> <title>start</title> <script language="c#" runat="server"> void Page_Load(object sender, System.EventArgs e) { String selectCmd = "select * from Recording"; SqlConnection myConnection = new SqlConnection( "server=(local);database=recordings;Trusted_Connection=yes"); SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection); DataSet ds = new DataSet(); myCommand.Fill(ds, "Recording"); recordingSelect.DataSource = ds; recordingSelect.DataTextField = "title"; recordingSelect.DataValueField = "id"; recordingSelect.DataBind(); } </script> </head> <body> <asp:dropdownlist id="recordingSelect" runat="server" /> <asp:button runat="server" text="Submit" OnClick="SubmitBtn_Click" /> </form> </body> </html>Now, consider I have different files for
---- View and Code-behind spearated ----
.aspx
.aspx.cs
using System; using System.Data; using System.Data.SqlClient; public class Solution : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { String selectCmd = "select * from Recording"; SqlConnection myConnection = new SqlConnection( "server=(local);database=recordings;Trusted_Connection=yes"); SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection); DataSet ds = new DataSet(); myCommand.Fill(ds, "Recording"); recordingSelect.DataSource = ds; recordingSelect.DataTextField = "title"; recordingSelect.DataValueField = "id"; recordingSelect.DataBind(); } }1. Seeing the above msdn page link for the Controller class, I am not able to discern the difference between the business logic (that would have been similar for a middle tier in a 3 tier architecture) and the controller.<br/>
2. Is 3-tier and MVC completely different thing? Are the ASP.NET application in Visual Studio already separated file as in MVC form? If these are not different, which one is the preferred style?<br/>
3. What's the MVC framework about then if the .aspx and .aspx.cs are already spearated?
[1]: http://msdn.microsoft.com/en-us/library/ff647462.aspx
Harpreet
thinkrajesh
Participant
1356 Points
232 Posts
Re: Difference between MVC controller and business logic (3 tier)
Mar 17, 2012 12:09 PM|LINK
MVC falls under architectural pattern and is primarily concerned with UI and interaction logic separation. The other layers of the 3 tier will still be applicable.
The most common MVC frameworks usually follow a Front Controller pattern. i.e. rather than request getting landed to a specific page, the request is routed to a common front controller, whose sole responsibility is to invoke the specific requested controller based on information passed in the querystring or as part of the request.
Ideally the controller should be as thin as possible and its sole responsibility should be to infer the request and call appropriate business or data access service. There shouldn't be any business specific logic in the controller.
My recommendation is to look at the ASP.NET MVC implementation for more information as this is built on the industry adopted best practices...
(Don't forget to click "Mark as Answer" on the post(s) that helped you.)
techbits
Member
3 Points
7 Posts
Re: Difference between MVC controller and business logic (3 tier)
May 28, 2012 06:03 AM|LINK
Where do we implement the business logic? Can you please give me a small example to show, how is it implemented?
blurearc
Contributor
3710 Points
692 Posts
Re: Difference between MVC controller and business logic (3 tier)
May 28, 2012 07:14 AM|LINK
YOur Model is the right place to start with Business logic. you can write your Business logic in WCF service and use it in Model. Youcan writ4e youe BL in Seprate Assembly.
ther places you don't write youe business logic or you avide them are:
View, View Model, controller.
Controller should not have heafty coding, Controller should pass the incomming values from View to Model and let' model work on incomming request.
"There are NO shortcuts for success, better stop taking one."
Ravi Kant Srivastava