Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Invisible methods from abstract class in derived with interface

Maybe the title is not super good, but simply saying I did not have a better idea for it. The current situation in the project: I have some repositories (each for one table in DB) and I have created an abstract base class for all of them:

public abstract class BaseRepository<T> where T :  class, new()
{
    public ISession _session;
    public BaseRepository()
    {
        _session = Database.NHibernateHelper.OpenSession();
    }

    public async Task<T> Get<PK>(PK Id)
    {
        return await _session.GetAsync<T>(Id);
    }

    public async Task<List<T>> All()
    {
        return (List<T>) await _session.QueryOver<T>().ListAsync();
    }
}

Now I have an implementation for User table for example:

public class UserRepository : BaseRepository<Database.Entities.User>, IUserRepository
{       
    public UserRepository()
    {
    }

    public async Task AddUser(User user)...

Code for the interface:

 public interface IUserRepository
 {
    Task AddUser(User user);

What I would like to do now, is inject this interface (IUserRepository) to my UserService class (using Autofac). The problem that I faced is that the UserService class cannot find the implementation of function "Get" - which is defined in the BaseRepository. Can someone please explain to me how this should be done? I assume that the interface IUserRepository does not have the definition of Get() method, but then how to solve this issue? Do I have to specify the BaseRepository methods in all interfaces for other repositories which I do have?

Kindest regards for the answer.

[EDIT] After trying, this is what I have: IBaseRepository:

 public interface IBaseRepository<T> where T : class

BaseRepository:

 public abstract class BaseRepository<T> : IBaseRepository<T> where T :  class,  new()

IUserRepository:

  public interface IUserRepository<T> : IBaseRepository<T> where T : class

UserRepository:

   public class UserRepository : BaseRepository<User>, IUserRepository<User>

Does this make sense? :)

Comments