Spiria logo.

FubuMVC. Fubu what?

April 2, 2013.

In 2009, Microsoft launched their new application framework ASP.NET MVC 1.0. We could finally use Microsoft technologies and apply good web practices. Despite this, ASP.NET MVC had its flaws.

To overcome its shortcomings, several respectable programmers in the field decided to create another application framework in .Net whose goal was not to make development easy for the average person, but rather to implement good development practices. Thus, in early 2011 (or late 2010, I'm not sure), was born "For Us By Us MVC" better known as "For Us By Us MVC". FubuMVC.

As any good open source project FubuMVC remained beta for a good 2 years to arrive at an official version 1.0 released in January 2013. So I decided to get into FubuMVC and do my first tests.

The first steps

To start a FubuMVC project, it's very simple:

  1. Creating an Asp.Net Empty Web App Application
  2. Via Nuget, install FubuMVC

That's done, you can compile and launch the application... but where are the views, the controllers, and how does it work? Now the fun begins.

To start, start the application and go to the page " /_fubu/routes " (this page will become your best friend). This is the list of links available for the application, you can double click on a line to get more information.

With FubuMVC, it is possible to put views and controllers in any directory or namespace. But for now we will stick to the convention suggested by FubuMVC.

What used to be controllers in ASP.NET MVC are now classes whose names end with "Endpoint" or "Endpoints".

What is suggested by the Fubu team is to name "actions" or methods with a prefix "get_" or "post_" followed by the name of the method. The underlined characters " _ " will become slashes " / ". For example, "_" will become a slash "/":

  1. get_Read will have as link "/Read" and available only in "get".
  2. get_Read_Book will have as link " /Read/Book ", available only in " get ".
  3. Post_Book_Update will have as link /Book/Update available only in "post".

You can play with the method and class names and go back to " _fubu/routes ".

Hello World

For my "HelloWorld", what I did :

  1. Create a directory « Book »
  2. Create a class « BookViewModel » public class BookViewModel { public string Name { get; set; } }
  3. Create a class « BookEndpoint » with the method « get_Book_Detail »
    
    public class BookEndpoint
    {
        public BookViewModel get_Book_Detail()
        {
            return new BookViewModel { Name = "Some Book Title" };
        }
    }
  4. Create a "Razor" view whose model is "BookViewModel".
  5. I compile, launch the application and go to "/Book/Detail" and it works.

Note that :

  1. I don't have a class that inherits "ControllerBase".
  2. I did not put the controller in the "Controller" folder and the view in the "Views" folder.
  3. I don't have a method that returns an "ActionView".

The "magic" of FubuMVC is able to match the returned object to the view . In fact, one of the good practices they apply is the « One Model In, One Model Out ». That is, each action must have a unique object as input parameter (or have no input parameter at all) and the returned object must also be unique (or return nothing).

This gives me a class that is my controller, but will be much easier to test than ASP.NET MVC controllers.

Conclusion

FubuMVC lacks documentation. At least, it is not easy to find and it is not always up to date. But when you take the time to learn it, it becomes quite contagious and we want to know more.

There's a lot to explore and that's what I'm going to do to come back with more complete examples.