UPDATE - Please look at my answer for a link and explanation of the solution to this problem
Before we start, I know this is a very common quest
I was getting this issue but only on Web Service calls. Found my solution on this answer https://stackoverflow.com/a/12379938/129580 below is the sample code provided
public class Service : WebService
{
public IContextProvider ContextProvider {get;set;}
public Service()
{
ContextProvider = DependencyResolver.Current.GetService();
}
}
which I then ended up turning into, hope this helps...
///
/// Summary description for PartMarking
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class PartMarking : System.Web.Services.WebService
{
private readonly IUnitOfWork _unitOfWork;
public PartMarking()
{
_unitOfWork = DependencyResolver.Current.GetService();
}
[WebMethod]
public DataSet GetParentConfigurations(string engineModel, string componentCode)
{
var results = _unitOfWork.PartMarking.GetParentSicMarkings(engineModel, componentCode);
return results;
}
}