This project is read-only.

Converting to MVC

Sep 23, 2008 at 2:48 AM
I'm proud to announce that we will finally move to MVC.  Since we can expect a beta coming up soon and hopefully a final release by the end of the year it's a good time to begin converting the code over.$0$0$0$0I've branched the project until things stablize.$0
Sep 23, 2008 at 12:45 PM
Which branch should I be working on?
Sep 23, 2008 at 2:42 PM
If your ok with things not compiling than you can work on the Mvc feature branch, otherwise stick to main branch until the basic MVC stuff is working.
Sep 24, 2008 at 8:15 AM
Great news... will be interesting to see how routing and the AtomPub service document all fit together.

Currently on part 7 (with only 14 to go!) of Rob Conery's excellent Sotrefront series... very helpful... :-)
Sep 24, 2008 at 9:20 AM
It should be interesting ... if I ever get finished with the LINQ data layers.
Sep 26, 2008 at 9:05 PM
Edited Sep 26, 2008 at 9:07 PM
I started by using the built in routing mechinism but it is much more restrictive and would break threading and paging.  However, the routing is extensible and I was able to reuse the RegEx from the Url Rewriting. So, all the existing URL formats can remain under MVC.  Also, via the IRouteService we could alter the URL formats to fit in with "MVC" style URLs.
Sep 27, 2008 at 3:08 AM
Edited Sep 27, 2008 at 3:12 AM
I've been reading about Routes and Handlers for the past few hours... getting there... and as a learning exercise, getting ready to port my photos gallery to Mvc.. as well as create an NVelocity view engine (out of curiosity more than anything.. will be interested to compare the two).

Also noticed your RegexRoute. Another good find. :-)

Purely cosmetic... but I'd be tempted to create extension methods for this class as well moving....

static void AddRegexRoute(string regex, string controller, string action)
{
    RouteTable.Routes.Add(
        new RegexRoute(regex, new MvcRouteHandler())
        {
            Defaults = new RouteValueDictionary(new { controller = controller, action = action })
        }
    );
}

over to... to the RegexClass source file (in a static RegexRouteExtentions class) as....

static RegexRoute MapRegexRoute(this System.Web.Routing.RouteCollection routes, string name, string regex, string controller, string action)
{
    RegexRoute item = new RegexRoute(regex, new MvcRouteHandler())
                          {Defaults = new RouteValueDictionary(new {controller = controller, action = action})};
   
    routes.Add(name, item);

    return item;
}

Also giving the route a name... means that if we ever wanted to use the NamedRoute class that Stephen Walther created, as a base class for all routes.. we could use his fancy Custom Route debugger inspired by Phil Haack's ASP.NET Routing Debugger..

Ok - well I couldn't resist... this barely amounts to more than 'tinkering'.. but I've done the above. Feel free to 'undo' it if it's not right, or gets in the way...
Sep 27, 2008 at 11:44 AM
Ok, I am working in the Respository and Repository.Test projects on the main branch. I assume that these won't change on the MVC branch.
Sep 27, 2008 at 8:07 PM
Edited Sep 28, 2008 at 4:31 PM
@Abouch: yea great idea, I've applied it to the rest of the routes

@AnthonySteele: that's a safe area to work, I'm about 90% there to merging MVC branch back into main.
Sep 28, 2008 at 5:47 PM
Was experimenting a little more today with view engines and rendering...

I might be miles off... but I think for the BaseEntryControl, and BaseFeedControl you might be able to use the Microsoft.Web.Mvc.ViewExtensions.RenderAction helper method.

The helper will take you back into a controller to get the extra model data and view template... as opposed to the view requesting the data directly from a static service class like... Feed = Global.AtomPubService.GetFeed(Source, 0, MaxEntries);

You could use ..  <%Html.RenderAction<AtomPubController>(x => x.Feed('tag:blogsvc.net,2008:blog', 'atom', 4));%>

...or <%Html.RenderAction(AtomPubController, Feed('tag:blogsvc.net,2008:blog', 'atom', 4));%>

Possibly a little pedantic..and maybe not a priority, but I've been wondering about exactly this situation. Like how you would create the equivalent of a webpart... or a widget... but that doesn't rely on the ViewData from the parent view, and still follows the MVC approach (especially if you wanted to add or remove widgets to the initial template - without having to create a giant chunk of ViewData to cover all possibilities).

The RenderAction helper method works for sure with the WebForms view engine. I've seen it in StoreFront, and have tried it as well in a test application I've been working on. Not so lucky with the NVelocity ViewEngine... as the view output doesn't render in the correct order - spitting the control template out at the very top of the response stream :-(
Sep 28, 2008 at 6:05 PM
Edited Sep 28, 2008 at 6:12 PM
@Abouch, great feedback and exactly what I was hoping to get.  I'll take a look at the RenderAction method.  I know that everything isn't pure MVC yet so these suggestions are great.  Also, all the talk about sub-controllers is supposedly exactly for this purpose.  Take a look at Brad Wilson's blog about partial views to understand the order issue with other view engines.
Sep 28, 2008 at 6:40 PM
Edited Sep 28, 2008 at 6:46 PM
@jarrettv - yeah I was reading Brad's post... very helpful and a very good explanation of how view templates are 'discovered', in particular when multiple view engines are available. That was the first thing I checked out in my test app creating templates for more than one view engine. Some really interesting possibilities here.. since if we made each of the available view engines 'theme' aware... we can let anyone build any theme using any view templating scheme they want :-) Very cool.

The problem with Partial views as far as I could tell - was that they rely on the parent view's ViewData... ok for simpler templates that can rely on the parent view... but not great for a widget style control.

Thanks for the link to the SubControllers post... that's exactly what I was looking for (I checked-out MvcContrib earlier today but didn't know it was there!). Will investigate further... :-)
Sep 29, 2008 at 3:10 PM
Edited Sep 29, 2008 at 3:29 PM

We need to do some research on how to properly support widgets, repository extensibility, macros, etc in the MVC framework.

 

The MVC change over is complete.  I am preparing and testing for release 0.6 which will be called the “MVC Release.”  I’m hoping we make some waves in the .net community with this release since we are using some of the hottest technologies: MVC, jQuery, AtomPub. We’ll need to get the word out by kickin some articles, etc.

 

I’m proud of the switch from WCF “RestAtomPubService” over to MVC “AtomPubController” since things are now fully testable as all the methods return ActionResults.  The change over not only simplified authentication but also reduced complexity of current and future Ajax support.  Furthermore, things work great within VisualStudio's built in development server so new developers or tech users can fire things up without any hassel.

I’ve learned that WCF is really only practical for quick (and simple) REST support on top of existing services.  For complex REST scenarios, WCF is a pain.

 

Overall, the switch to MVC was fairly straight forward and is definitely exciting.

Sep 29, 2008 at 4:09 PM
Nice one Jarrett. Wo-hoo! :-)

Anything in particular we can help with on the testing front? When will you merge back into Main?
Sep 30, 2008 at 12:09 AM
I've been totally swamped the last few weeks, so I have been sitting on the sidelines watching this great progress. I really look forward to doing some screencast stuff with 0.6. It looks like things might free up later this week or into next week.
Sep 30, 2008 at 9:36 AM
Neat :)

Linq to SQL support is not complete yet (and not close) but it is progressing,
Sep 30, 2008 at 9:30 PM
@Abouch: I've done a fair amount of testing and tweaking already with MVC.  However, you could do a get latest and see if I missed anything.  I'll probably release 0.6 late tonight.

@jwynia: looking forward to your screencasts

@AnthonySteele: keep up the great work
Oct 1, 2008 at 2:50 AM
@jarrettv - should we be getting the latest from the Mvc feature branch, or Main?
Oct 1, 2008 at 4:42 AM
The main branch.
Oct 2, 2008 at 5:40 PM
Edited Oct 2, 2008 at 6:20 PM
MVC Release 0.6 is now available.  Check it out and be sure to kick this entry: http://blogsvc.net/blog/2008/10/02/Release06.xhtml
Oct 3, 2008 at 12:53 AM
Edited Oct 3, 2008 at 12:54 AM
Looks good Jarrett.. !
Oct 8, 2008 at 8:08 PM
@Abouch: Thanks!  I've recently added date/time support which has configurable timezone.  I'm also using the cool jQuery Time Ago plugin.  Checkout my post on this: http://blogsvc.net/blog/2008/10/08/NewGlobalDateAndTimeSupport.xhtml