Question

How can I use my IoC container in a DataService and the CurrentDataSource inside for WCF Data Services? I have several services I want to pass into it. The "host" application or project for the DataService is based on ASP.NET MVC 2.0. My IoC container is setup in the MvcApplication.

Was it helpful?

Solution

This is not as "clean" as integrating your IoC container deep into the WCF factory classes but if you want to supply a DataSource you could use the Common Service Locator (link at bottom) with your existing IoC container and override the CreateDataSource method of DataService

protected override MyEntityContext CreateDataSource() 
{
    return ServiceLocator.Current.GetInstance<MyEntityContext>();
}

Common Service Locator library

http://commonservicelocator.codeplex.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top