I have a project that has three layer.
1st is the DAL
2nd is the Domain
3rd is the Presentation
I created an interface in my Domain Layer (ICategoryRepository) here is the Code
public interface ICategoryRepository
{
List<CategoryDTO> GetCategory();
}
and I created a class in my DAL to implement the ICategoryRepository in my Domain.
public class CategoryRepository : ICategoryRepository
{
BookInfoContext _context;
public List<CategoryDTO> GetCategory()
{
_context = new BookInfoContext();
var categoryDto = _context.Categories
.Select(c => new CategoryDTO
{
CategoryId = c.CategroyId,
CategoryName = c.CategoryName
}).ToList();
return categoryDto;
}
}
Then I create a class in my Domain and pass the ICategoryRepository as parameter in my constructor.
public class CategoryService
{
ICategoryRepository _categoryService;
public CategoryService(ICategoryRepository categoryService)
{
this._categoryService = categoryService;
}
public List<CategoryDTO> GetCategory()
{
return _categoryService.GetCategory();
}
}
I do this to invert the control. Instead of my domain will depend on DAL I invert the control so that myDAL will depend on my DOMAIN.
My Problem is, everytime I call the CategoryService in the Presentation Layer I need to pass ICategoryRepository as parameter of constructor which is in the DAL. I don't want my Presentation Layer to be dependent in my DAL.
Any suggestion?
Thanks,