I am trying to configure a simple project for Azure to use a WCF service with Http bindings, and using Autofac's WCF integration. Currently I am testing locally and hosting under IIS (Azure).
First I set up the project to run without Autofac and can instantiate the service and see the WSDL endpoint exposed through a browser.
I then modified the services svc file and added a Factory definition.
<%@ ServiceHost Language="C#" Debug="true" Service="EposDataService" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>
I next modified the WebRole class:
public override void Run()
{
// This is a sample worker implementation. Replace with your logic.
Trace.WriteLine("Worker entry point called", "Information");
var builder = new ContainerBuilder();
builder.RegisterModule(new ServiceModule());
//using (m_Container = builder.Build())
m_Container = builder.Build();
//{
AutofacHostFactory.Container = m_Container;
while (true)
{
// sleep 30 minutes. we don't really need to do anything here.
Thread.Sleep(1800000);
Trace.WriteLine("Working", "Information");
}
//}
}
However when I deploy the service locally and try and access the service, I get an error:
The AutofacServiceHost.Container static property must be set before services can be instantiated.
Exception Details: System.InvalidOperationException: The AutofacServiceHost.Container static property must be set before services can be instantiated.
What I don't understand is that the static property is being set in the WebRole but it appears as if something is resetting the assignment. Any suggestions?