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:
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
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:
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