Saturday, March 26, 2011

FuBuMVC - WebForms

FubuMVC is a plugable framework when User interface comes into play. It can be easily switched from WebForm view-engines to Spark. Other view-engines will be supported in near future.

However, By default WebForm view-engine is available in all samples and there is one convention that is applied for all WebForm pages. For example, if you have a page called HomePage.aspx and your page is inherited from a class called HomePage.

<%@ Page Language="C#" Inherits="MyProject.UI.Actions.Home.HomePage" %>
then HomePage class should be inherited from FubuPage and implements like that :

    public class HomePage : FubuPage
    {
    }

Where "HomeViewModel" is the exact object returned from HomeAction's Execute method ( last post). That means after an action is executed, the returned object is hanged to its own page by convention. By this approach, developers don't need to worry about their code-behind class(such as what we have in WebForm) and of course, if they go to other view-engines. Because, all business codes are in Execute Method.

 

FubuMVC - Actions

FubuMVC is shipped with a sample called DarthFubuMVC on GitHub. If you looak at the project, It has some sort of folder structure like what we have in Asp.Net MVC. In there, you can find Actions folder which is similar to Controllers in Asp.Net MVC.

Generally speaking, Fubu is designed based on One Model In - One Model Out. i.e you as developer have to define a type of object as input argument (model) and define another type of object as return value.

The example below explains more in code.

    public class HomeAction
    {
        public HomeViewModel Execute(HomeInputModel model)
        {
            return new HomeViewModel();
        }

    }

     public class HomeInputModel
    {
    }
     public class HomeViewModel
    {
    }

Every Action/Controller class should have Execute method, in order to run. While this method as mentioned above, should have unique object as input and output.

By default, Fubu's routing engine runs HomeAction's execute method when it reaches the url like this:

http://MyPrject.Com/Home.

As stated in previous posts, all suffixes like action,Command, Query... is ignored due to simplicity of Fubu's routing system. Jeremy fully explained the routing system's internals in this post