The following program using Autofac in conjunction with Nancy does not launch the default Nancy server correctly.
using Autofac;
using Nancy.Hosting.Self;
using System;
namespace NancyExample
{
class Program
{
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.Register(c => new NancyHost(new Uri("http://localhost:8080"))).SingleInstance();
using (var container = builder.Build())
{
NancyHost host = container.Resolve<NancyHost>();
// this fails with:
// Exception thrown: 'System.Net.HttpListenerException' in System.dll
// Exception thrown: 'System.Net.HttpListenerException' in System.dll
// Exception thrown: 'System.InvalidOperationException' in System.dll
// Exception thrown: 'System.InvalidOperationException' in System.dll
// this works:
// NancyHost host = new NancyHost(new Uri("http://localhost:8080"));
host.Start();
}
Console.ReadLine();
}
}
}
When resolving NancyHost via Autofac, it appears that an error comes deep within .NET's HttpListener. There doesn't seem to be good details on this exception. Visiting http://localhost:8080 results in no connection.
Instantiating NancyHost myself works fine.
Using:
- Autofac 4.3
- Nancy 1.4.3
- Nancy.Hosting.Self 1.4.1
NancyHostfrom the container? It's not using the container at all? - khellangHttpListener. Nancy doesn't even touchHttpListenerbefore callingStart. - khellang