Didaxis
Didaxis

Reputation: 8756

Ninject WCF Error

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; }
    }
}

Upvotes: 2

Views: 1446

Answers (2)

Didaxis
Didaxis

Reputation: 8756

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!

Upvotes: 1

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65461

This could be caused by SqlUserIssueRepository not implementing IUserIssueRepository.

Ninject is trying to bind the class to the interface.

Upvotes: 0

Related Questions