问题,今天我在使用Ajax的时候,发现请求到后台没法得到对象。

原来的写法是这样的:

public class Baoming : IHttpHandler
    {
        [Inject]
        public IBLL.IChildrensInfo ChildrensInfoBLL { get; set; }
public void Save()
{
//下面就直接使用 ChildrenInfoBLL,报错未将引用设置到对象的实例
}
}

 

后来查到了一个方法:

public void Save()
{
IKernel kernel = new StandardKernel();
            kernel.Bind<IBLL.IChildrensInfo>().To<BLL.ChildrensInfo>();
            kernel.Bind<IDAL.IChildrensInfo>().To<DAL.ChildrensInfo>();
            IBLL.IChildrensInfo ChildrensInfoBLL = kernel.Get<IBLL.IChildrensInfo>();
//......
}

好了,问题解决。

还有一个问题是:在一般处理程序中使用 NInject 的时候,还可以用另一个办法:WebServiceBase。之前不知道,后来查到的,

让ashx继承WebServiceBase 就好了:

public class GetUserMsgHandler : WebServiceBase, IHttpHandler{

[Inject]

public IBLL.IChildrensInfo ChildrensInfoBLL { get; set; }//接下来就可以正常使用了

}

参考:http://www.cnblogs.com/JustYong/p/5882416.html

相关文章:

  • 2021-08-19
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-09-04
  • 2021-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-27
  • 2021-07-29
  • 2021-12-08
  • 2022-12-23
  • 2021-09-10
相关资源
相似解决方案