将 Ninject.Extensions.Wcf 用于 ASP.NET MVC 2 中托管的 Web 服务
我正在 wcf Web 服务中使用 ninject。此 Web 服务托管在创建为“ASP.NET MVC 2 空 Web 应用程序”的项目中。
它使用 Ninject.dll v2 和 Ninject.Extensions.Wcf.dll v1 的引用。
服务文件的标记是
<%@ ServiceHost
Language="C#"
Debug="true"
Service="wcf_ninject.Service1"
CodeBehind="Service1.svc.cs"
Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory" %>
global.asax 继承自 NinjectWcfApplication
public class Global : NinjectWcfApplication
{
protected override IKernel CreateKernel()
{
return new StandardKernel(new WCFNinjectModule());
}
}
,
public class WCFNinjectModule : NinjectModule
{
public override void Load()
{
Bind<IRepository>().To<EFRepository>();
// rest of bindings
}
}
该服务的唯一构造函数是:
public Service1(IRepository repository)
{
_repo = repository;
}
大多数时候工作正常,但有时我会收到错误:
“激活 Service1 时出错 多个匹配绑定可用”
但正如所说,我无法找到复制路径。
i am using ninject in a wcf web service.This web service is hosted in a project created as a "ASP.NET MVC 2 Empty Web Application".
It is using the references for Ninject.dll v2 and Ninject.Extensions.Wcf.dll v1.
The markup for the service file is
<%@ ServiceHost
Language="C#"
Debug="true"
Service="wcf_ninject.Service1"
CodeBehind="Service1.svc.cs"
Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory" %>
The global.asax is inheriting from NinjectWcfApplication
public class Global : NinjectWcfApplication
{
protected override IKernel CreateKernel()
{
return new StandardKernel(new WCFNinjectModule());
}
}
with
public class WCFNinjectModule : NinjectModule
{
public override void Load()
{
Bind<IRepository>().To<EFRepository>();
// rest of bindings
}
}
and the only constructor for the service is:
public Service1(IRepository repository)
{
_repo = repository;
}
Most of the time works fine, but from time to time i get the error:
"Error activating Service1 More than one matching bindings are available"
But as said i am unable to find a reproduction path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您使用的是旧版本。我记得在 2.1 甚至 2.0 中存在隐式绑定的多线程问题。它应该在 2.2 和 3.0 中修复。
I assume you are using an older version. I can remember there was a multithreading issue with implicit bindings in 2.1 or even 2.0. It should be fixed in 2.2 and 3.0.