ASP.NET MVC 4 + Ninject MVC 3 = No parameterless constructor defined for this object

前端 未结 17 1512
猫巷女王i
猫巷女王i 2020-11-30 01:41

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

17条回答
  •  暖寄归人
    2020-11-30 02:31

    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;
        }
    }
    

提交回复
热议问题