TopShelf.Owin
Topshelf.Owin provides extensions to configure a self-hosted OWIN instance along with your service class.
Install / Use
/learn @dennisroche/TopShelf.OwinREADME
Topshelf.Owin

Extend TopShelf to be a self-hosted API using OWIN (Open Web Interface for .NET)
NB: Owin requires .NET 4.5 or later.
How to use
Install the Nuget package.
Install-Package Topshelf.Owin
Then modify your TopShelf service.
using Topshelf;
using TopShelf.Owin;
namespace YourService
{
internal class Program
{
static void Main(string[] args)
{
HostFactory.Run(c =>
{
c.RunAsNetworkService();
c.Service<YourService>(s =>
{
s.ConstructUsing(() => new YourService());
s.WhenStarted((service, control) => service.Start());
s.WhenStopped((service, control) => service.Stop());
s.OwinEndpoint(app =>
{
app.Domain = "localhost";
app.Port = 8080;
});
});
});
}
}
}
If you want to use with AutoFac, then also add AutoFac.WebApi and TopShelf.AutoFac packages and then set the DependencyResolver.
s.OwinEndpoint(app =>
{
app.UseDependencyResolver(new AutofacWebApiDependencyResolver(container));
}
By default, it will map routes using attributes on the actions. If you want to change the HttpCongfiguration to change routes or change the JSON serializer, you can:
s.OwinEndpoint(app =>
{
app.ConfigureHttp(httpConfiguration =>
{
httpConfiguration.MapHttpAttributeRoutes();
httpConfiguration.Formatters.Clear();
httpConfiguration.Formatters.Add(new JsonMediaTypeFormatter());
var jsonSettings = httpConfiguration.Formatters.JsonFormatter.SerializerSettings;
jsonSettings.Formatting = Formatting.Indented;
jsonSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
});
If you want to bind any OWIN app/middleware other than WebAPI, you can do so by accessing the IAppBuilder instance directly, e.g.:
s.OwinEndpoint(app =>
{
app.ConfigureAppBuilder(appBuilder => appBuilder.UseNancy());
});
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
