Starting an MVC# application means just starting one of its
tasks. In our case we will start the Main Task. The common place in ASP.NET
programs for the initial task staring code is the session start handler (in
Global.asax file).
Listing 19
<!---------------------- Global.asax file -------------------->
<script runat="server">
...
public void Session_Start(object sender, EventArgs e)
{
TasksManager tm = new TasksManager(WebformsViewsManager.
GetDefaultConfig());
tm.StartTask(typeof(MainTask));
}
As seen above, we are using a TasksManager instance to start
the task. However, each tasks manager requires some configuration before using
it. Above, we are passing a standard configuration object intended for Web
applications to the tasks manager constructor.
The last thing left to do is to define mapping between views
and corresponding web pages. For this we should add the following code to the
Global.asax <script> block.
Listing 20
<!---------------------- Global.asax file -------------------->
<script runat="server">
...
[WebformsView(typeof(MainTask), MainTask.Welcome, "Default.aspx")]
[WebformsView(typeof(MainTask), MainTask.ProductCategories,
"ProductCategories.aspx")]
[WebformsView(typeof(MainTask), MainTask.Products, "Products.aspx")]
[WebformsView(typeof(MainTask), MainTask.EditProduct, "EditProduct.aspx")]
class ViewDescriptions { }
That is all, we have successfully finished our example
application and it is ready to run!