Packaging a Library as Either AppHostBase or AppSelfHostBase


I’ve been working on a Service Stack project which I’d like to re-use in a variety of contexts.

At the moment I’ve accomplished this by having a library WebApplicationHost which derives from AppSelfHostBase. (WebApplicationHost only really overrides Configure in order to provide runtime configuration.)

When I want to re-use this library I create a new application, instantiate WebApplicationHost and then manually register any additional Services which I want to include.

The problem is that when I re-use this class I’m limited to Console applications because I’ve extended from AppSelfHostBase and for some projects I’d like to target IIS as the hosting platform.

What’s the best way to build a ServiceStack application with a common Configure function but which can target either a stand-alone app or an IIS application?

Alternatively, is this whole idea a mistake, and I should just accept some code duplication in the AppHost configuration?

Many thanks!


Just refactor out the common code, have a look at how we do this in Gistlyn to share common AppHost configuration between the ASP.NET and SelfHosting/Desktop Apps.

1 Like