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,
ISmallBizRepositoryinterface
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
}
SmallBizRepositoryclass
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
}
BaseQueryHelperclass
public class BaseQueryHelper
{
private IQueryHelperRepository _repo;
public BaseQueryHelper(IQueryHelperRepository repo)
{
_repo = repo;
}
protected IQueryHelperRepository TheRepository
{
get
{
return _repo;
}
}
}
IQueryHelperRepositoryinterface
public interface IQueryHelperRepository
{
#region Firm
IQueryable GetClient(Guid firmid);
IQueryable GetClient(Guid firmid, Guid id);
#endregion
}
QueryHelperRepositoryclass
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
}
BaseApiControllerclass
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.