Modularity via Bottles

“My biggest pain point is my curiosity about the Bottles project. When you guys mention it, I feel like there’s some secret game for grown ups, and I’m not allowed.”  - Artëm Smirnov


This is a very common sentiment. Today my goal is to help set the record straight and begin the daunting task of introducing something that I think is going to revolutionize the .NET ecosystem: Bottles.

Rather than speaking at a 50,000 foot level, I’m going to dive right into how FubuMVC uses the framework and we can abstract from there.

Since I will be using FubuMVC as a basis for this explanation, I strongly suggest you spend some time understanding FubuMVC before reading about these advanced topics. Visit our portal to get started.

Case Study: FubuMVC – Advanced Diagnostics

When building a FubuMVC application, you may be familiar with the baseline diagnostics that we ship. These are available when you include them in your FubuRegistry (IncludeDiagnostics(true)):

FubuMVC Diagnostics

Notice the route for diagnostics: ~/_fubu

Now let’s go ahead and install the FubuMVC.Diagnostics package. If we go to the same route, we’ll see something that looks more like this:

The advanced diagnostics package adds more functionality, more styles, and a little more class to the baseline diagnostics. It replaces the existing functionality and can be used with any FubuMVC application.

What just happened?
Let’s talk a little bit about how the Advanced Diagnostics package is built and then we’ll discuss the magic that happens when you “install” it. Of course, we’ll also discuss what it means to “install a package”.

Building the Package

One very important thing to note about the Advanced Diagnostics package is this: it’s built almost exactly like a typical FubuMVC Application. That means it has its own conventions, handlers, views, etc. The package can be heavily tested like any other FubuMVC application and you can expect the same great experience all the way through.

There are only two small differences to note when constructing a package:

  1. Making use of FubuPackageRegistry instead of FubuRegistry
  2. The .package-manifest file

The package manifest file tells FubuMVC what it’s dealing with (e.g., name, assemblies to take with you, views, etc.). We’ll discuss FubuPackageRegistry when we discuss package installation.

Creating a Package

The creation of a package is quite simple. It can be a manual or automated process – either way, we’ll make use of the tooling that Bottles provides: BottleRunner.exe.

A command for creating the advanced diagnostics package might look like this:

BottleRunner.exe create-pak src/FubuMVC.Diagnostics -target DEBUG

This will simply create a zip file for us in a format that Bottles can understand (the contents are derived by the spec provided in your package manifest file).

Installing the Package

Like the creation of packages, the installation of packages is also very simple. It can be a manual process or an automated one (via the Bottles.Deployment goodies). To keep things simple, I’ll use the manual process to avoid the forced introduction of yet another tool.

The FubuMVC infrastructure for Bottles knows of a special directory within the root directory of your application called “fubu-content”. So we take the zip file that was created for us by BottleRunner.exe, and we copy/paste it into our fubu-content directory. Now we start up our application and voila, magic happens.

Wrap Up

This post is already longer than I wanted it to be so I’m going to leave you on a bit of a cliffhanger: “how does the magic happen? What other things can I do with this?” Those are questions that you should be asking and ones that I will address in a future post.


About Josh Arnold

Josh is team lead at Extend Health and a principal developer on the Fubu-family of frameworks. He is a proud husband, terrified but excited father, passionate software guy and coach, closet musician, aspiring man of God, and a perpetual learner.
This entry was posted in General and tagged , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Jonathan Matheus

    Very interesting! What’s the development story for bottles? With MvcContrib’s portable areas, these things are embedded in a dll, so a simple project reference would suffice during development. Can something similar be done with bottles?

    • Anonymous

      We go a little further and allow the files to actually be blown out so it’s taken us a little bit of time to lock down the development story. Development mode can still be an install if you really want to but we also support the concept of “aliases” and “links”. 

      Links allow you include packages relative to your path (e.g., include ../FubuMVC.Diagnostics would include the FubuMVC.Diagnostics project that’s presumably in the same solution).

      I’ll be talking more about what they can do and how to do it in upcoming posts. Hopefully that will answer the questions of “why do they exist?”

      • Josh, I think this is perfect material for a webcast :)

      • Josh, I think this is perfect material for a webcast :)

    • As Josh said, there’s a “linking” mechanism to just reference an external project on the file system as a “Bottle” for development mode (it would work in production mode too, but I’m not entirely sure why you’d do that).  

      Also, Bottles does not require you to embed any resources, views, content, what have you if you use the Zip file mode.

  • Pingback: The Morning Brew - Chris Alcock » The Morning Brew #931()

  • WantsAnAbstract

    WTF is Bottles?

  • Does bottles support inter-bottle dependencies? 

    • Anonymous

      This is something that has come up a few times. The short answer is: no but soon. Unless of course someone added it and I don’t know about it.

  • Neil Sorensen

    This is an old post, so I’m not expecting an update, but the FubuMVC.Diagnostics package has moved: