Ninject WCF 错误
好吧,在过去两天寻找这个错误后,我已经束手无策了:
Error activating IUserIssueRepository
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency IUserIssueRepository into parameter userIssueRepository of constructor of type IssueTrackerService
1) Request for IssueTrackerService
Suggestions:
1) Ensure that you have defined a binding for IUserIssueRepository.
2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
3) Ensure you have not accidentally created more than one kernel.
4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
5) If you are using automatic module loading, ensure the search path and filters are correct.
我知道我的设置是正确的(绑定完好无损等)。这里是相关的wcf服务内容。是的,当然,装配参考也完好无损。
Global.asax.cs 使用 Ninject; 使用 Ninject.Extensions.Wcf;
namespace NextGenIT.Web.Wcf
{
public class Global : NinjectWcfApplication
{
protected override IKernel CreateKernel()
{
return new StandardKernel(new ServiceModule());
}
}
}
ServiceModule.cs
using Ninject.Modules;
using NextGenIT.Core.Domain;
namespace NextGenIT.Web.Wcf
{
public class ServiceModule : NinjectModule
{
public override void Load()
{
this.Bind<IUserIssueRepository>()
.To<SqlUserIssueRepository>();
}
}
}
IssueTrackerService.svc
<%@
ServiceHost
Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory"
Service="NextGenIT.Core.Services.IssueTrackerService"
%>
编辑 1: 整个堆栈跟踪:
[FaultException`1: Error activating IUserIssueRepository
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency IUserIssueRepository into parameter userIssueRepository of constructor of type IssueTrackerService
1) Request for IssueTrackerService
Suggestions:
1) Ensure that you have defined a binding for IUserIssueRepository.
2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
3) Ensure you have not accidentally created more than one kernel.
4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
5) If you are using automatic module loading, ensure the search path and filters are correct.
]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4729827
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725
NextGenIT.Services.Contracts.IIssueTrackerService.GetUserIssues(String userId) +0
NextGenIT.Services.Client.IssueTrackerClient.GetUserIssues(String userId) in D:\Projects\TFS\NextGenIssueTracker\branches\2011Updates\NextGenIT.Services.Client\Proxies\IssueTrackerClient.cs:46
NextGenIT.Tests.Integration.WebClient._default.Page_Load(Object sender, EventArgs e) in D:\Projects\TFS\NextGenIssueTracker\branches\2011Updates\NextGenIT.Tests.Integration.WebClient\default.aspx.cs:26
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064
编辑 2:接口和实现
IUserIssueRepository.cs
using System.Collections.Generic;
using NextGenIT.Services.Contracts;
namespace NextGenIT.Core.Domain
{
public interface IUserIssueRepository
{
string CreateUser(IUser user);
int CreateIssue(IIssue issue);
int CreateComment(IComment comment);
IUser GetUser(string userId);
IIssue GetIssue(int issueId);
IEnumerable<IIssue> GetIssues(string userId);
IEnumerable<IComment> GetComments(string userId, int issueId);
}
}
SqlUserIssueRepository.cs
using System.Collections.Generic;
using NextGenIT.Services.Contracts;
namespace NextGenIT.Core.Domain
{
public class SqlUserIssueRepository : IUserIssueRepository
{
public string CreateUser(IUser user) { return "1234"; }
public int CreateIssue(IIssue issue) { return 1; }
public int CreateComment(IComment comment) { return 1; }
public IUser GetUser(string userId) { return null; }
public IIssue GetIssue(int issueId) { return null; }
public IEnumerable<IIssue> GetIssues(string userId) { return null; }
public IEnumerable<IComment> GetComments(string userId, int issueId) { return null; }
}
}
OK, I'm at my wits end after hunting this error down for the past two days:
Error activating IUserIssueRepository
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency IUserIssueRepository into parameter userIssueRepository of constructor of type IssueTrackerService
1) Request for IssueTrackerService
Suggestions:
1) Ensure that you have defined a binding for IUserIssueRepository.
2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
3) Ensure you have not accidentally created more than one kernel.
4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
5) If you are using automatic module loading, ensure the search path and filters are correct.
I know my settings are correct (bindings intact, etc). Here are the relevant wcf service stuff. And yes, of course the assembly references are intact as well.
Global.asax.cs
using Ninject;
using Ninject.Extensions.Wcf;
namespace NextGenIT.Web.Wcf
{
public class Global : NinjectWcfApplication
{
protected override IKernel CreateKernel()
{
return new StandardKernel(new ServiceModule());
}
}
}
ServiceModule.cs
using Ninject.Modules;
using NextGenIT.Core.Domain;
namespace NextGenIT.Web.Wcf
{
public class ServiceModule : NinjectModule
{
public override void Load()
{
this.Bind<IUserIssueRepository>()
.To<SqlUserIssueRepository>();
}
}
}
IssueTrackerService.svc
<%@
ServiceHost
Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory"
Service="NextGenIT.Core.Services.IssueTrackerService"
%>
Edit 1: entire stack trace:
[FaultException`1: Error activating IUserIssueRepository
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency IUserIssueRepository into parameter userIssueRepository of constructor of type IssueTrackerService
1) Request for IssueTrackerService
Suggestions:
1) Ensure that you have defined a binding for IUserIssueRepository.
2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
3) Ensure you have not accidentally created more than one kernel.
4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
5) If you are using automatic module loading, ensure the search path and filters are correct.
]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4729827
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725
NextGenIT.Services.Contracts.IIssueTrackerService.GetUserIssues(String userId) +0
NextGenIT.Services.Client.IssueTrackerClient.GetUserIssues(String userId) in D:\Projects\TFS\NextGenIssueTracker\branches\2011Updates\NextGenIT.Services.Client\Proxies\IssueTrackerClient.cs:46
NextGenIT.Tests.Integration.WebClient._default.Page_Load(Object sender, EventArgs e) in D:\Projects\TFS\NextGenIssueTracker\branches\2011Updates\NextGenIT.Tests.Integration.WebClient\default.aspx.cs:26
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064
Edit 2: interface and implementation
IUserIssueRepository.cs
using System.Collections.Generic;
using NextGenIT.Services.Contracts;
namespace NextGenIT.Core.Domain
{
public interface IUserIssueRepository
{
string CreateUser(IUser user);
int CreateIssue(IIssue issue);
int CreateComment(IComment comment);
IUser GetUser(string userId);
IIssue GetIssue(int issueId);
IEnumerable<IIssue> GetIssues(string userId);
IEnumerable<IComment> GetComments(string userId, int issueId);
}
}
SqlUserIssueRepository.cs
using System.Collections.Generic;
using NextGenIT.Services.Contracts;
namespace NextGenIT.Core.Domain
{
public class SqlUserIssueRepository : IUserIssueRepository
{
public string CreateUser(IUser user) { return "1234"; }
public int CreateIssue(IIssue issue) { return 1; }
public int CreateComment(IComment comment) { return 1; }
public IUser GetUser(string userId) { return null; }
public IIssue GetIssue(int issueId) { return null; }
public IEnumerable<IIssue> GetIssues(string userId) { return null; }
public IEnumerable<IComment> GetComments(string userId, int issueId) { return null; }
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:
在某个时候,我重命名了托管 WCF 服务的项目。我从未想过检查 global.asax 的标记。
事实上,它是从一个不再存在的文件继承的。项目编译没有问题,这就是为什么我从来没有想过去那里检查!
Update:
At some point I had renamed the project hosting the WCF service. I never thought to check the markup of the global.asax.
Indeed it was inheriting from a file that no longer existed. The project compiled no problem, that's why I never thought to check there!
这可能是由于 SqlUserIssueRepository 未实现 IUserIssueRepository 造成的。
Ninject 正在尝试将类绑定到接口。
This could be caused by SqlUserIssueRepository not implementing IUserIssueRepository.
Ninject is trying to bind the class to the interface.