2
我有以下的HttpHandler:HttpHandler的使用Ninject返回房產注入空
public class NewHandler : IHttpHandler
{
[Inject]
public IFile FileReader
{
get;
set;
}
public NewHandler()
{
}
public void ProcessRequest(System.Web.HttpContext context)
{
....
var something = SomeMethod(FileReader);
....
}
public bool IsReusable
{
get
{
return true;
}
}
}
這是我Ninject模塊在Global.asax。
internal class ServiceModule : NinjectModule
{
public override void Load()
{
Bind<IFile>().To<FileWrapper>().InSingletonScope();
}
}
每次處理程序觸發時,FileReader都是NULL。我錯過了什麼嗎?這是使用Ninject進行屬性注入的正確方法嗎?
謝謝
謝謝!我讀了這篇文章,很有意思。爲了試用它,我相應地修改了我的應用程序,但在ProcessRequest觸發時我仍然設法在FileReader屬性中獲得NULL。 – Thomas 2010-09-02 21:01:09
@Thomas - 查看我的更新 – Necros 2010-09-03 00:19:39
是的,該方法有效。仍然很好奇,爲什麼不能按照控制器的相同方式進行屬性注入。可能與請求管道有關。如果有人知道,請讓我知道。 Necros,再次感謝! – Thomas 2010-09-03 00:32:56