Ninject Activation Exception未被usercode处理 [英] Ninject Activation Exception was unhandled by usercode

查看:141
本文介绍了Ninject Activation Exception未被usercode处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在使用Web Api我收到错误事件控制器在调用事件控制器时没有默认构造函数,所以我跟着此链接。现在我在调用Event controller时出错。这是错误。



激活ICommandBus时出错

没有匹配的绑定可用,类型不可自绑定。

激活路径:

2)将依赖关系ICommandBus注入到EventController类型的构造函数的参数commandBus中

)对EventController的请求



建议:

1)确保为ICommandBus定义了绑定。

2)如果绑定是在模块中定义的,请确保模块已加载到内核中。

3)确保您没有意外创建多个内核。

4)如果使用构造函数参数,请确保参数名称与构造函数参数名称匹配。

5)如果使用自动模块加载,请确保搜索路径和过滤器正确。



这是我的ServiceModule类:

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





这是我的EventController



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





这是我的EventRepository和IEventRepository:



Here is my EventRepository and IEventRepository:

public class EventRepository : RepositoryBase<Event>, IEventRepository
    {
        public EventRepository(IDatabaseFactory databaseFactory)
            : base(databaseFactory)
        {
        }
    }
    public interface IEventRepository : IRepository<Event>
    {
    }





这是我的IcommandBus界面:

公共接口ICommandBus

{

ICommandResult提交< tcommand>(TCommand命令)其中TCommand:ICommand;

IEnumerable< validationresult>验证< tcommand>(TCommand命令),其中TCommand:ICommand;

}



-Thanks

Sindhu



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

推荐答案

这篇关于Ninject Activation Exception未被usercode处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆