【问题标题】:No matching bindings are available, and the type is not self-bindable.没有匹配的绑定可用,并且该类型不可自绑定。
【发布时间】:2016-03-15 23:09:59
【问题描述】:

我的绑定有什么问题?

    private static void RegisterServices(IKernel kernel)
    {
        kernel.Bind<IBaseRepository<User>>().To<UserRepository>();
    }    

我的 IBaseRepository

public interface IBaseRepository<TEntity> where TEntity : class
    {
        void Commit();
        void Delete(TEntity entity);
        void Delete(object id);
        void Dispose();
        IQueryable<TEntity> GetAll();
        IQueryable<TEntity> GetAll(object filter);
        TEntity GetById(object id);
        TEntity GetFullObject(object id);
        IQueryable<TEntity> GetPaged(int top = 20, int skip = 0, object orderBy = null, object filter = null);
        void Insert(TEntity entity);
        void Update(TEntity entity);
    }

还有我的 UserRepository

public class UserRepository : BaseRepository<User>
{
    public UserRepository(DataContext context) : base(context)
    {
        if(context == null)
            throw new ArgumentNullException();
    }
}

这是我收到的错误 激活 IBaseRepository{Role} 时出错 没有匹配的绑定可用,并且该类型不可自绑定。 激活路径: 2)将依赖IBaseRepository{Role}注入到UsersController类型的构造函数的参数角色中 1) 请求用户控制器

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-5 dependencies ninject code-injection


    【解决方案1】:

    您的异常消息清楚地表明IBaseRepository&lt;Role&gt; 的绑定丢失。 角色而不是用户

    所以添加

    kernel.Bind<IBaseRepository<Role>>().To<RoleRepository>();
    

    应该有帮助! ;-)

    【讨论】:

    • 非常感谢,我没注意到!
    猜你喜欢
    • 2015-06-26
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多