So you are thinking about using FubuMVC but you are having a hard time justifying to your coworkers or boss or even yourself the level of effort it would take to switch your existing ASP.NET MVC website over to a new web framework. You wish there was a way you could get into FubuMVC with the ability to slowly transition your site piece by piece and not all at once.

Or perhaps you are content using ASP.NET MVC for your project, but are interested in taking advantage of FubuMVC behavior chains to deal with common before and after request responsibilities.

It is the goal of the MvcToFubu project to help enable these two scenarios and encourage everyone to try FubuMVC out for themselves. By smoothing the transition away from ASP.NET MVC towards FubuMVC hopefully anyone who was sitting on the fence about giving Fubu a try will be able to check it out with less risk.

Clone from the github repository here:

https://github.com/bobpace/MvcToFubu

Make sure you have ASP.NET MVC 3 installed to view the sample projects.

Also, when you build for the first time it will have build errors before it pulls down the nuget package references, just build again and you will be good.

NOTE: Since FubuMVC runs on StructureMap, if your website uses a different container you will need to use StructureMap in order to take advantage of any of the techniques shown by this MvcToFubu project.

Part 1

Enable FubuMVC Behavior chains in your ASP.NET MVC web application.

I will assume some familiarity with behavior chains already but you can read more about them here:

http://guides.fubumvc.com/getting_started.html#behaviorsand-behavior-chains

After pulling down the MvcToFubu source and building, set the MVCWithFubuBehaviors project as the startup project and run it.

After arriving at the example view you can look in your Visual Studio Output window and you should see a line containing:

Executing example behavior...

This ExampleBehavior is set up in the ExamplePolicy class to be applied to all actions on the ExampleController.

I want to point out a few of the important pieces that help make this work.

MvcToFubuApplication

Creates and populates a BehaviorChainIdLookup that matches ASP.NET MVC controller action invocations to their corresponding behavior chain. This lookup is used in the MvcToFubuControllerActionInvoker so that when the normal ASP.NET MVC pipeline invokes a controller action it can defer the execution of the ActionResult until the MvcActionCall node in your behavior chain. Behaviors for OutputNodes, or nodes that come after the ActionCall are not supported since after running the MvcActionCall the default ASP.NET MVC rendering pipeline takes over.

MvcToFubuRegistry

Ignores methods that come from base ASP.NET MVC Controller class, since controllers will be inheriting it.

Replaces the default ActionCall in the behavior chain with our MvcActionCall which will enable us to invoke the regular ASP.NET MVC pipeline for the controller action.

ControllerContextBehavior

A base class for behaviors for your convenience since much of what you may want to deal with will be contained on the ControllerContext.

Part 2 will go over the details of how to run FubuMVC right inside your existing ASP.NET MVC site, letting you transition your site slowly to FubuMVC while maintaining existing ASP.NET MVC site functionality.

blog comments powered by Disqus