During some spare time last weekend I decided to look into booting up Umbraco outside of a web context. I know this has been done before in various different ways but for this I wanted to just try to use the Umbraco core. There are 2 things that are required to boot Umbraco:

  • IBootManager
  • UmbracoApplicationBase

In Umbraco source, there are a couple of these instances: CoreBootManager, WebBootManager & UmbracoApplication.  Essentially the WebBootManager starts up anything that has web requirements and inherits from CoreBootManager which starts up the rest of Umbraco and all of that is bootstrapped with UmbracoApplication, which is actually the instance of the global.asax in an Umbraco website. To boot just the core of Umbraco it would seem clear that I just want CoreBootManager and then bootstrap it myself with a custom UmbracoApplicationBase. All of this is actually very simple and the bare bones would look something like:

public class ConsoleApplication : UmbracoApplicationBase
{  
    public void StartApplication()
    {
        GetBootManager()
            .Initialize()
            .Startup(appContext => OnApplicationStarting(this, new EventArgs()))
            .Complete(appContext => OnApplicationStarted(this, new EventArgs()));
    }

    protected override IBootManager GetBootManager()
    {
        return new ConsoleBootManager();
    }
}

Then to use it could look something like:

public void Main()
{
    using (var app = new ConsoleApplication())
    {
        app.StartApplication();
        using (var appCtx = ApplicationContext.Current)
        {
            //do stuff
        }
    }
}

Let’s just say there are still some issues with this that we’ll iron out in the future. Almost all of the issues have to do with loading in plugins and plugins not being capable of running without web context, and various other things. The good news is that I got it working with only a tiny bit of reflection which basically just removes all IApplicationEventHandlers from starting up apart from the ones found in the Umbraco Core assembly.

LinqPad & Umbraco is real!

Knowing that I could boot Umbraco and interact with it’s data via the ApplicationContext, I figured the next best thing would be to see if I could get that working with LinqPad… and I did !  Awesome!! :)

So here you go, a shiny new v1.0 LinqPad driver for Umbraco and all of the source code:

Be sure to read the docs, there’s probably a lot of stuff it can’t do, but there’s certainly a lot of stuff it could do!!! The next version will hopefully have some proper IQueryable support which I’ve been working on as well.

See it in action:

Umbraco LinqPad driver