OK,我在我无计可施打猎这个错误下来,这两天后: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; 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"
%>
编辑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; }
}
}
有两件事情:1)当你把一个breakpoing int'Load',它会触发吗? 2)我们可以看到整个堆栈跟踪吗? –
Errr,实际上我不确定它是否被称为...如果不是,可能是什么原因? – Didaxis