Implementing Mobile BrowserCapabilitiesProvider

Topics: Core, Customizing Orchard
Nov 6, 2012 at 3:04 AM


In .NET 4 you can set a custom BrowserCapabilitiesProvider to add or override the default browser capabilities in Request.Browser. E.g.

protected void Application_Start()
    HttpCapabilitiesBase.BrowserCapabilitiesProvider = new MobileCapabilitiesProvider();

My question is, as this class is called by ASP.NET before the routing system, the ShellRoute has not been determined and IWorkContextAccessor is not set in the DataTokens, so what is the best way to get access to the current work context.

I want to be able to resolve services so that I can access my custom capability store and services.

I understand I could just copy what the OrchardServiceHostFactory does with the IShim and manual building of the IWorkContext. However is this the best approach as it would duplicate the building of the work context for every request.

I think this is important to resolve properly if we are to get good mobile support in Orchard.