how to use dependency injection with repository in mix mode

Viewed 64

i have the problem to use dependency injection in mix mode, mean one repository functions call in 2nd repository using inheritance, but i am not sure what i am mixing or what is wrong,

  1. ISmallBizRepository interface
public interface ISmallBizRepository
{
    #region Clients
    bool Insert(ClientsDM obj);
    bool Update(ClientsDM original, ClientsDM updated);
    ClientsDM GetClientsByPrimaryKey(Guid id);
    IQueryable GetClients(Guid id, Guid firmid);
    IQueryable GetClients(Guid firmid);
    bool DeleteClients(Guid id, Guid deletedby);
    #endregion
}
  1. SmallBizRepository class
public  class SmallBizRepository : BaseQueryHelper,ISmallBizRepository
{
   private SmallBizDbContext _ctx;
   public SmallBizRepository(SmallBizDbContext ctx)
   {
        _ctx = ctx;
   }
   public SmallBizRepository(IQueryHelperRepository repo)
        : base(repo)
   {
   }
   #region Clients
    public IQueryable GetClients(Guid firmid)
    {
        return TheRepository.GetClient(firmid);
    }
    #endregion
}
  1. BaseQueryHelper class
public class BaseQueryHelper
{
    private IQueryHelperRepository _repo;
    public BaseQueryHelper(IQueryHelperRepository repo)
    {
        _repo = repo;
    }

    protected IQueryHelperRepository TheRepository
    {
        get
        {
            return _repo;
        }
    }
}
  1. IQueryHelperRepository interface
public interface IQueryHelperRepository
{
    #region Firm
    IQueryable GetClient(Guid firmid);
    IQueryable GetClient(Guid firmid, Guid id);
    #endregion
}
  1. QueryHelperRepository class
   public class QueryHelperRepository : IQueryHelperRepository
   {
    private SmallBizDbContext _ctx;
    public QueryHelperRepository(SmallBizDbContext ctx)
    {
        _ctx = ctx;
    }
    #region Firm
    public IQueryable GetClient(Guid firmid)
    {
        var Clientjc = from a in _ctx.Client
                       join b in _ctx.AflAwmAddrBook on a.AddressBookId equals b.AddressBookId into ab
                       from b1 in ab.DefaultIfEmpty()
                       where (a.DeletedOn == null && a.FirmId == firmid)
                       orderby a.CreatedDate descending
                       select new
                       {
                           a.FirmId,
                           a.ClientId,
                           a.FirstName,
                           a.LastName,
                           a.Email,
                           a.Phone,
                           a.Address,
                           a.City,
                           a.ZipCode,
                           a.State,
                           a.Country,
                           a.UserId,
                           a.PayPalEmail,
                           a.EmailApprovedDate,
                           a.IsApproved,
                           a.DeletedBy,
                           a.DeletedOn,
                           a.CreatedDate,
                           a.AddressBookId,
                           AflAwmAddrBook_fullname = b1.fullname,
                           a.Picture,
                       };

        return Clientjc;
    }
    #endregion
    }
  1. BaseApiController class
    public class BaseApiController : ApiController
    {
    private ISmallBizRepository _repo;
    private ModelFactory _modelFactory;

    public BaseApiController(ISmallBizRepository repo)
    {
        _repo = repo;
    }

    protected ModelFactory TheModelFactory
    {
        get
        {
            if (_modelFactory == null)
            {
                _modelFactory = new ModelFactory(Request, TheRepository);
            }
            return _modelFactory;
        }
    }

    protected ISmallBizRepository TheRepository
    {
        get
        {
            return _repo;
        }
    }
}

the above repository classes working separately, but when we Inherit QueryHelperRepository with SmallBizRepository and use function like this

    #region Clients
    public IQueryable GetClients(Guid firmid)
    {
        return TheRepository.GetClient(firmid);
    }
    #endregion

in SmallBizRepository.

please help/guide me in this problem, i appreciate your valuable time.thanks in advance.

1 Answers
Related