2011-09-26 78 views
2

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

有兩件事情:1)當你把一個breakpoing int'Load',它會觸發嗎? 2)我們可以看到整個堆棧跟蹤嗎? –

+0

Errr,實際上我不確定它是否被稱爲...如果不是,可能是什麼原因? – Didaxis

回答

1

更新:

在某些時候,我已經更名爲託管WCF服務項目。我從來沒有想過檢查global.asax的標記。

的確,它是從一個不再存在的文件繼承而來的。該項目編譯沒有問題,這就是爲什麼我從來沒有想過在那裏檢查!

0

這可以通過SqlUserIssueRepository引起不執行IUserIssueRepository。

Ninject試圖將類綁定到接口。

+0

不,它絕對實現了IUserIssueRepository – Didaxis

+0

你可以發佈界面嗎? –