How can i build a repository container so that i dont have to inject each and every custom repository using constructor injections in controller or application service layers. following is my plan:
public interface ISupplierRepository
{
ISupplierProfileRepository _supplierProfileRepository { get; }
ISupplierBusnsServicesRepository _supplierBusnsServiceRepository { get; }
ISupplierBusnsCoverageRepository _supplierBusnsCoverageRepository { get; }
ISupplierPhotosRepository _supplierPhotosRepository { get; }
ISupplierVideosRepository _supplierVideosRepository { get; }
ISupplierLeadsRepository _supplierLeadsRepository { get; }
ISupplierCertificationsRepository _supplierCertificationsRpository { get; }
}
but currently i am getting an unsatisfied dependency injection error on ISupplierRepository as i havnt implemented this interface using RepositoryBase. because RepositoryBase can only implement using a specific domain type.
Hey there ! i need your help to figure me out that how the different scripts will work on my page . following is the procedure i followed to bundle my scripts Script Path=> define the variable with its link =>Include in BundleConfig .. but my scripts are not loading the thing which i want is on the image i have attached
Thanks bro. It did resolve my problem already.
I tried everything as mentioned, but I am getting different errors on your different suggestions. Let me list the two which I want to use: 1.Your suggestion to use
_supplierRepository.FirstOrDefault(t=>t.TenantId==AbpSession.TenantId);
is not retrieving the supplier object from db and Throwing a null object reference at the time of first usage in following method:
public List<SupplierBusnsServiceDto> GetSupplierBusnsService()
{
return Mapper.Map<List<SupplierBusnsServiceDto>>(_supplierProfile.supplierbusnsServices);
}
I have created a one-one relation with Tenant because I am trying to build a Supplier Profile architecture, which will have its business services, photos , videos and other tables. All of these will be child tables of the SupplierProfile Entity. My db model looks like following:
public SupplierAppServices(IRepository<SupplierProfile> supplierRepository)
{
_supplierRepository = supplierRepository;
_supplierProfile = GetCurrentTenant().supplier; // or
//_supplierProfile = supplierRepository.Get(AbpSession.TenantId.Value);
}
Note that all of this is in my AppService Class, where all methods of this class are UOW by default and should get the Repository using dependency injection. And by using AppServiceBase inheritance i should be able to get the TenantManager and UserManager methods like GetCurrentTenant and GetCurrentUser. But i am getting error on calling GetCurrentTenant() in my constructor that "Must set UnitOfWorkManager before use it" on following line in my AppServiceBase Class
Line 60: using (CurrentUnitOfWork.SetTenantId(null))
Line 61: {
Line 62: return TenantManager.GetById(AbpSession.GetTenantId());
Summary: First Try is not giving data because there is a null object reference errors because the repository object is not retrieving data from db. Second try is not giving tenant because UOW is not set where as i am calling the GetTenantId from my app service Constructor.
I strongly hope that you will guide me with better programming logic and a permanent solution.
Hi Hikalkan , Yes I read that documentation last night and I think I should call ToList() method after the getall method.
Anyways I need a little more help. Can you please give me sample code snippet to lazy load my supplier. Also note that my supplier and tenant entities are in one to one relationship having a navigation object in each entity class. Do you recommend calling a GetCurrentTenant () method in my AppService constructor to load my supplier object?
I am getting above error as soon i am accessing the repository to get records in the SetSupplier() method. I am using IRepository<SupplierProfile> supplierRepository as constructor injection in my SupplierAppService Class. review code below: (My SupplierProfile Entity is having a one-one relationship with the Tenant, and it is also implementing IMusthaveTenant, Please guide if i can avoid the Where clause from my query as IMustHaveTenant should implement it. )
class SupplierAppServices: FixonClickAppServiceBase, ISupplierAppServices
{
private readonly IRepository<SupplierProfile> _supplierRepository;
private SupplierProfile _supplierProfile;
public SupplierAppServices(IRepository<SupplierProfile> supplierRepository)
{
_supplierRepository = supplierRepository;
SetSupplier();
}
private void SetSupplier()
{
_supplierProfile = _supplierRepository.GetAll().Where(t=>t.TenantId==AbpSession.TenantId).FirstOrDefault();
}
Hi Doubleday, I tried downloading from the above link but the link is broken. Can you send another link. Arslan.