Bla*_*keH 9 ninject ninject.web.mvc asp.net-mvc-4
我在NinjectWebCommon.RegisterServices方法中为HttpContextBase创建了一个绑定,但是当我尝试在我的控制器或服务中引用它时,我收到一条错误消息.
这是绑定:
kernel.Bind<HttpContextBase>().ToMethod(context => new HttpContextWrapper(HttpContext.Current)).InRequestScope();
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
Error activating HttpContextBase
More than one matching bindings are available.
Activation path:
2) Injection of dependency HttpContextBase into parameter abase of constructor of type HomeController
1) Request for HomeController
Suggestions:
1) Ensure that you have defined a binding for HttpContextBase only once.
Run Code Online (Sandbox Code Playgroud)
如果我删除绑定,那么它似乎做我想要的(解析为HttpContextWrapper),但我想知道如何注册?
Dar*_*rov 20
但我想知道这是如何注册的?
查看源代码,MvcModule.cs您的问题将立即得到解答:
this.Kernel.Bind<HttpContext>().ToMethod(ctx => HttpContext.Current).InTransientScope();
this.Kernel.Bind<HttpContextBase>().ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InTransientScope();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2991 次 |
| 最近记录: |