PDA

View Full Version : DI and InstanceContextMode.Single


chrc2
08-04-2008, 10:54 AM
Using the WcftQuickStart example, i get the following error when i change the instanceContextMode to Single(ton). Is there another way of starting up the DI container?

Error creating context 'spring.root': root context is currently in creation. You must not call ContextRegistry.GetContext() from e.g. constructors of your singleton objects

Bruno Baia
08-04-2008, 11:24 AM
Hi,

thanks for reporting this.
We are investigating, and try to fix it for the WCF release.

Looks like there is the same pb with Oran Dennison approach (http://orand.blogspot.com/2006/10/wcf-service-dependency-injection.html).


A solution is to comment the ServiceExporter definition in the configuration file and use the programmatic way :
See Program.cs file in the Spring.WcfQuickStart.ServerApp console project :

// Programmatically (You need to comment 'ServiceExporter' object definition in App.config)
using (ServiceHost serviceHost = new ServiceHost("calculator"))
{
serviceHost.Open();

Console.Out.WriteLine("Server listening...");
Console.Out.WriteLine("--- Press <return> to quit ---");
Console.ReadLine();
}


The problem is that ServiceExporter also start a ServiceHost, and it should not.


- Bruno