将 Ninject.Extensions.Wcf 用于 ASP.NET MVC 2 中托管的 Web 服务

发布于 2025-01-08 21:36:58 字数 1046 浏览 3 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满意归宿 2025-01-15 21:36:58

我假设您使用的是旧版本。我记得在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文