Click here to Skip to main content
15,898,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am Using Web Api Prevously I am getting error Event Controller doesnot have default constructor while calling event controller, so i followed this link. Now i am getting error while calling Event controller.Here is the error.

Error activating ICommandBus
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency ICommandBus into parameter commandBus of constructor of type EventController
1) Request for EventController

Suggestions:
1) Ensure that you have defined a binding for ICommandBus.
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.

Here is my ServiceModule class:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EFMVC.Data.Repositories;
using Ninject.Modules;

namespace EFMVC.Web.API.Custom
{
    public class ServiceModule : NinjectModule
    {
        public override void Load()
        {
            Bind<ICustomerRepository>().To<CustomerRepository>().InSingletonScope();
            Bind<IEventRepository>().To<EventRepository>().InSingletonScope();
            Bind<ICategoryRepository>().To<CategoryRepository>().InSingletonScope();
        }
    }
}


Here is my EventController
C#
public class EventController : ApiController
   {

       private readonly IEventRepository eventRepository;
     private readonly JsonResponseHandler jsonResponseHandler;
       [Inject]
       public EventController(ICommandBus commandBus, IEventRepository eventRepository)
       {
           this.commandBus = commandBus;
           this.eventRepository = eventRepository;
       }
   public HttpResponseMessage Get()
   {
       return Request.CreateResponse(HttpStatusCode.OK,jsonResponseHandler.rootDictionary, jsonResponseHandler.formatter);
   }


Here is my EventRepository and IEventRepository:
C#
public class EventRepository : RepositoryBase<Event>, IEventRepository
    {
        public EventRepository(IDatabaseFactory databaseFactory)
            : base(databaseFactory)
        {
        }
    }
    public interface IEventRepository : IRepository<Event>
    {
    }


Here is my IcommandBus interface:
public interface ICommandBus
{
ICommandResult Submit<tcommand>(TCommand command) where TCommand : ICommand;
IEnumerable<validationresult> Validate<tcommand>(TCommand command) where TCommand : ICommand;
}

-Thanks
Sindhu
Posted
Updated 1-Apr-14 2:06am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900