Ian Cooper's profileStaccato SignalsBlogLists Tools Help

Blog


    November 14

    What is the MVC noise all about, anyway? Pt 2

    Monorail and ASP.NET MVC

    Now, if you are sold on the principle of clean separation of your model, view and controller, and you want to start using application controllers and separated views then you could roll your own implementation. A better solution however is to use an off-the-shelf alternative to WebForms such as Monorail or, in the future perhaps, the ASP.NET MVC framework to provide this type of framework.

     

    Monorail

    The Castle Project was founded by Hamilton Verissimo de Oliveira originally to develop an Inversion of Control container but later expanded its mission to common enterprise and web applications. Key projects include: MicroKernel & Windsor IoC containers, the MonoRail web framework, Active Record for NHibernate, Aspect # AOP framework, and a Dynamic Proxy generator.

     

    Monorail is an MVC web framework built on the ASP.NET platform.

     

    Monorail has distinct controllers and views. This makes the controllers easy to test. A Monorail controller for example looks something like this:

     

       [Layout("default"), Rescue("generalerror")]

        public class ProductController : SmartDispatcherController

        {

            public void List()

            {

                 PropertyBag["products"] = Product.FindAll();

                 RenderView("list");

            }

        }

     

    Here ProductController is our controller, identified by its base class (ultimately Controller). The controller exposes a number of public methods, which Monorail terms actions. Actions are requests to the controller – to provide a response to a request. Within the action we ask the model (Product) for data, which we pass to the view (via PropertyBag) for display. We then pick an appropriate view and tell it to render (Monorail will actually render the view with the same name as the action by default – we just show it here for clarity).

     

    MonoRail, acting as the front controller, decides which (application) controller to display using the url of the request. The url which has the form <site>\<area>\<controller>\<action>.rails

     

    The view is a template written in NVelocity (though you can use other view engines like Brail), that takes the data from the model (via the property bag) and generates html for the response:

     

    <h3>Product list</h3>

     

    <p>

    <a href="new.rails">Create new Product</a>

    </p>

     

    <table width="100%" border="1" cellpadding="2" cellspacing="0">

    <tr>

        <th>Id</th>

        <th>Name</th>

        <th>Supplier</th>

        <th>&nbsp;</th>

    </tr>

    #foreach($product in $products)

    <tr>

        <td align="center">$product.Id</td>

        <td align="center">$product.Name</td>

        <td align="center">$product.Supplier.Name</td>

        <td align="center">

            <a href="edit.rails?id=${product.Id}">Edit</a> |

            <a href="delete.rails?id=${product.Id}">Delete</a>

        </td>

    </tr>

    #end

    </table>

     

    Monorail uses a composite view pattern equivalent to master pages. Note that on the controller class we attribute the Layout. The layout is the master for the controller and the view we render in response to the request is the child of this master.

     

    In this case our layout looks like:

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

        <title>Layout</title>

        <link rel="stylesheet" href="$siteRoot/Content/css/base.css" />

    </head>

       

    <body>

     

    $childContent

       

    </body>

     

    </html>   

     

    Where $childContent is the placeholder for our view.

     

    The model is just a Plain Old C# object, likely representing an object within our domain. In this case we have a simple Product object. We use the Castle Project’s Active Record framework build on NHibernate to provide persistence for this object:

     

    [ActiveRecord]

    public class Product : ActiveRecordBase

    {

        [PrimaryKey]

        public int Id {get;set;}

     

        [Property]

        public string Name {get;set;}

     

        [Property]

        public decimal Price {get;set;}

     

        [BelongsTo("SupplierId")]

        public Supplier Supplier {get;set;}

           

        public static Product[] FindAll()

        {

            return (Product[]) FindAll(typeof(Product));

        }

           

        public static Product FindById(int id)

        {

            return (Product) FindByPrimaryKey(typeof(Product), id);

        }

    }

     

    Hopefully you can see the clean separation of concerns that MonoRail enables.

     

    You can work through the example this code was taken from at: http://www.castleproject.org/monorail/gettingstarted/index.html

     

    More...

    Comments (45)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    No namewrote:
    darkfall gold http://www.playerassist.com/darkfall/ darkfall online gold
    florensia gelt florensia gelts http://www.playerassist.com/florensia/
    florensia gelts
    talisman gold http://www.playerassist.com/talisman/ talisman online gold
    dofus powerleveling http://www.playerassist.com/dofus/dofus-power-leveling.php dofus power leveling
    lineage 2 powerleveling http://www.playerassist.com/lineage2/lineage2-power-leveling.php lineage 2 power leveling l2 powerleveling l2 power leveling

    Apr. 1
    No namewrote:
    darkfall gold http://www.playerassist.com/darkfall/ darkfall online gold
    florensia gelt florensia gelts http://www.playerassist.com/florensia/
    florensia gelts
    talisman gold http://www.playerassist.com/talisman/ talisman online gold
    dofus powerleveling http://www.playerassist.com/dofus/dofus-power-leveling.php dofus power leveling
    lineage 2 powerleveling http://www.playerassist.com/lineage2/lineage2-power-leveling.php lineage 2 power leveling l2 powerleveling l2 power leveling


    Mar. 31
    No namewrote:

    Gaia Gold GaiaOnline Gold http://www.playerassist.com/gaia/ Gaia Online Gold
    dofus kamas http://www.playerassist.com/dofus/buy dofus kamas cheap dofus kamas buy cheap dofus kamas
    eve isk eve online isk http://www.playerassist.com/eve/ eve isk on sale eve isk for sale, buy eve isk, cheap eve isk buy cheap eve online isk
    buy tibia money, cheap tibia gold, cheap tibia money, cheapest tibia gold, cheap tibia money, tibia gold for sale, tibia money for sale<a href="http://www.playerassist.com/maple-story/">maple story mesos</a>tibia gold, tibia money, buy tibia gold,
    Mar. 31
    No namewrote:
    It was not long <a href="http://www.gold4power.com/">cheap wow gold</a>before some one knocked at<a href="http://www.gold4power.com/">wow gold cheap </a> <a href="http://www.gold4power.com/">wow gold for sale</a>the house-door and called, open the door, dear children, your mother is here, and has brought something back with her for each of you. But the little <a href="http://www.wow8gold.net">wow8gold</a>kids knew that it was the wolf, by the rough voice. We will <a href="http://www.gold4power.org/">gold4power</a> not open the door, cried they, you are not our mother. She has a soft, pleasant voice, but your voice is rough, you are the wolf.

    Then the wolf went <a href="http://www.itemchannel.com">World Of Warcraft Gold</a>away to a shopkeeper and bought himself a great <a href="http://www.gold4power.com/">cheapest wow gold</a>lump of chalk, ate this and made <a href="http://www.mmogap.org.">mmogap</a> his voice soft with it. The he came back, knocked at the door of the house, and <a href="http://www.igsky.net">igsky </a>called, open the door, dear children, your mother is here and <a href="http://www.gold4power.com">Cheapest Wow Gold</a>has brought something back with her for each of you.

    Mar. 27
    No namewrote:
    http://www.batteryfast.co.uk/hp/f2024b.htm hp f2024b battery,
    http://www.batteryfast.co.uk/hp/dv8000.htm hp dv8000 battery,
    http://www.batteryfast.co.uk/hp/dv8100.htm hp dv8100 battery,
    http://www.batteryfast.co.uk/hp/dv8200.htm hp dv8200 battery,
    http://www.batteryfast.co.uk/hp/dv8300.htm hp dv8300 battery,
    http://www.batteryfast.co.uk/hp/hstnn-db20.htm hp hstnn-db20 battery,
    http://www.batteryfast.co.uk/hp/nx6120.htm hp nx6120 battery,
    http://www.batteryfast.co.uk/hp/pb994a.htm hp pb994a battery,
    http://www.batteryfast.co.uk/hp/nc6100.htm hp nc6100 battery,
    http://www.batteryfast.co.uk/hp/nc6120.htm hp nc6120 battery,
    http://www.batteryfast.co.uk/hp/nx6100.htm hp nx6100 battery,
    http://www.batteryfast.co.uk/hp/6515b.htm hp 6515b battery,
    http://www.batteryfast.co.uk/hp/nx6325.htm hp nx6325 battery,
    http://www.batteryfast.co.uk/hp/hstnn-db11.htm hp hstnn-db11 battery,
    http://www.batteryfast.co.uk/hp/nc8230.htm hp nc8230 battery,
    http://www.batteryfast.co.uk/hp/nc8200.htm hp nc8200 battery,
    http://www.batteryfast.co.uk/hp/nw8200.htm hp nw8200 battery,
    http://www.batteryfast.co.uk/hp/nx8200.htm hp nx8200 battery,
    http://www.batteryfast.co.uk/hp/nc8430.htm hp nc8430 battery,
    http://www.batteryfast.co.uk/hp/pb992a.htm hp pb992a battery,
    http://www.batteryfast.co.uk/hp/nc6000.htm hp nc6000 battery,
    http://www.batteryfast.co.uk/hp/nx5000.htm hp nx5000 battery,
    http://www.batteryfast.co.uk/hp/nw8000.htm hp nw8000 battery,
    http://www.batteryfast.co.uk/hp/nc8000.htm hp nc8000 battery,
    http://www.batteryfast.co.uk/hp/v1000.htm hp v1000 battery,
    http://www.batteryfast.co.uk/hp/nx4300.htm hp nx4300 battery,
    http://www.batteryfast.co.uk/hp/b1800.htm hp b1800 battery,
    http://www.batteryfast.co.uk/hp/hstnn-a14c.htm hp hstnn-a14c battery,
    http://www.batteryfast.co.uk/hp/b1829tu.htm hp b1829tu battery,
    http://www.batteryfast.co.uk/hp/b2000.htm hp b2000 battery,
    http://www.batteryfast.co.uk/hp/hstnn-b071.htm hp hstnn-b071 battery,
    http://www.batteryfast.co.uk/hp/lb32111b.htm hp lb32111b battery,
    http://www.batteryfast.co.uk/hp/dv2000.htm hp dv2000 battery,
    http://www.batteryfast.co.uk/hp/dv2100.htm hp dv2100 battery,
    http://www.batteryfast.co.uk/hp/dv2200.htm hp dv2200 battery,
    http://www.batteryfast.co.uk/hp/dv6000.htm hp dv6000 battery,
    http://www.batteryfast.co.uk/hp/520.htm hp 520 battery,
    http://www.batteryfast.co.uk/hp/500.htm hp 500 battery,
    http://www.batteryfast.co.uk/hp/hstnn-ib44.htm hp hstnn-ib44 battery,
    http://www.batteryfast.co.uk/hp/nc4000.htm hp nc4000 battery,
    http://www.batteryfast.co.uk/hp/nc4010.htm hp nc4010 battery,
    http://www.batteryfast.co.uk/hp/dd880.htm hp dd880 battery,
    http://www.batteryfast.co.uk/hp/315338-001.htm hp 315338-001 battery,
    http://www.batteryfast.co.uk/ibm/02k7072.htm ibm 02k7072 battery,
    http://www.batteryfast.co.uk/ibm/thinkpad-x40.htm ibm thinkpad x40 battery,
    http://www.batteryfast.co.uk/ibm/thinkpad-x60.htm ibm thinkpad x60 battery,
    http://www.batteryfast.co.uk/ibm/thinkpad-r32.htm ibm thinkpad r32 battery,
    http://www.batteryfast.co.uk/ibm/thinkpad-r40.htm ibm thinkpad r40 battery,
    http://www.batteryfast.co.uk/ibm/thinkpad-r40e.htm ibm thinkpad r40e battery,
    http://www.batteryfast.co.uk/ibm/thinkpad-t60.htm ibm thinkpad t60 battery,
    Dec. 11
    Dec. 1
    Picture of Anonymous
    (名前なし) wrote:
    Nov. 27
    No namewrote:
    toshiba pa33842u-1brs battery toshiba pa3384u-1bas battery toshiba pa3291u battery toshiba satellite p20 battery toshiba satellite p25 battery toshiba pa3250u battery toshiba satellite 2430 battery toshiba satellite a30 battery toshiba pa3356u-1bas battery toshiba satellite a50 battery toshiba satellite a55 battery toshiba pa3399u-1bas battery toshiba satellite a100 battery toshiba satellite m100 battery toshiba pa3534u-1brs battery toshiba satellite a205 battery toshiba pa3535u-1bas battery toshiba satellite a200 battery toshiba satellite m200 battery toshiba pa3536u-1brs battery toshiba pa3536u battery toshiba satellite p200 battery toshiba satellite p205 battery toshiba pa3062u-1bar battery toshiba tecra 8200 battery toshiba pa3369u-1bas battery toshiba satellite m18 battery toshiba satellite m19 battery toshiba pa3055u-1bas battery toshiba satellite 1700 battery toshiba pa3210u battery toshiba satellite 1110 battery toshiba satellite 1115 battery acer btp-550p btp-550 bat30n3l batby27l laptop battery Battery ACER Travelmate 4200 4203 4230 4260 4280 laptop battery acer travelmate 430 420 batbcl11 laptop battery acer travelmate 240 aspire 1610 btp-58a1 laptop battery acer travelmate c100 c102 c104 btp-42c1 laptop battery acer BTP-37D1 Travelmate 610 series laptop battery acer btp-63d1 btp-agd1 3020 3610 laptop battery acer BTA0302001 Aspire 1300 series laptop battery New battery fit Acer LIP-4084QUPC SQU-401 5000 laptop battery acer tm btp-650 btp-800sy squ-202 laptop battery laptop battery for 3UR18650F-3-QC151 tm3200 laptop battery acer BTP-ARJ1 2420 series laptop battery acer 1800 series batecq60 laptop battery apple powerbook g4 a1022 a1079 m9324 laptop battery apple a1045 a1078 e68043 m9325 m9756 laptop battery NEW Hi-Cap 5500mAh Battery for MacBook 13 A1185 WHITE laptop battery
    Nov. 26
    Nov. 18
    Nov. 18
    Nov. 4
    Nov. 3
    Nov. 3
    No namewrote:

    Hi,Do you need digital signages, advertising displays, digital sign, advertisement displays and advertising players? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.

    amberdigital Contact Us

    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[dajbjidifeiehd]

    Oct. 20
    Oct. 19
    Oct. 9
    No namewrote:

    Hi,Do you need advertising displays, digital signages, ad players, advertisement player and LCD advertisings? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers. amberdigital Contact Us

    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[dgjedcfaffeaacg]

    Sept. 24
    No namewrote:

    品川デリヘル高級デリヘル, 品川デリヘル品川の品川デリヘル店「品川デリヘル東京」では高級感ある極上なひとときをご提供します。品川デリヘル高級デリヘル, 品川デリヘル品川の品川デリヘル店「品川デリヘル東京」では高級感ある極上なひとときをご提供します。

    Sept. 2
    No namewrote:
    男性下着のことならプロパガンダ。他にも男性下着、ビキニ、マ男性下着、トランクスからセクシー系まで。男性下着のことならお任せください。"男性下着のことならプロパガンダ。他にも男性下着、ビキニ、マ男性下着、トランクスからセクシー系まで。男性下着のことならお任せください。"
    Sept. 2
    No namewrote:
     精力剤,勃起薬,勃起精力剤,勃起機能低下,インポ,  ,カマグラ,  精力剤,MAX,  精力剤 精力剤,勃起薬,勃起精力剤,勃起機能低下,インポ,  ,カマグラ,  精力剤,MAX,  精力剤
    Sept. 2

    Trackbacks

    The trackback URL for this entry is:
    http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!532.trak
    Weblogs that reference this entry
    • None