2
votes

What's wrong with my binding?

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

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

And my UserRepository

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

This is the error I recive Error activating IBaseRepository{Role} No matching bindings are available, and the type is not self-bindable. Activation path: 2) Injection of dependency IBaseRepository{Role} into parameter roles of constructor of type UsersController 1) Request for UsersController

1

1 Answers

2
votes

Well your exception message clearly states that the binding for IBaseRepository<Role> is missing. Role not User.

So adding

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

should help! ;-)