Is it a bad practice to expose DbContext in your service layer?
For Example:
private readonly IRepository<SkillLevels> _repository;
private readonly IDatabaseFactory _databaseFactory;
private readonly IUnitOfWork _unitOfWork;
public SkillLevelService(IRepository<SkillLevels> repository, IDatabaseFactory databaseFactory, IUnitOfWork unitOfWork)
{
_repository = repository;
_databaseFactory = databaseFactory;
_unitOfWork = unitOfWork;
}
public void InsertSkillLevel(SkillLevels entity)
{
_repository.Insert(entity);
_unitOfWork.Commit();
}
Here, IDatabaseFactory can return my DbContext object. I exposed it here because if i need other entities other than SkillLevels, so that i can use them in this service class. In case you know, for complex queries when you need to select multiple tables to fetch data.
But i'm not sure if it makes a bad practice!!
Any help is appreciated. Thanks.