I want to use Dtos to transfer data to service.I tried putting it in the business layer, but there is a problem.
My architecture similarly looks like this:
Core Layer (Dependencies:-)
-Entity Models
-Interfaces of Repositories
-Interfaces of Services
Data Layer (Dependencies:Core Layer)
-DbContext
-DbMappings
-Repositories
Business Layer (Dependencies: Core Layer, Data Layer)
-Services
-DTOs ???
WebApp Layer Business Layer (Dependencies: Core Layer, Data Layer, Business Layer)
-Controllers
-Views
-View Models, etc
I read the data from the form in the controller, convert it to SaveProductDto and send it to the service. Service takes Dto as a parameter, but I cannot give dto as a parameter to the interface of the method in the service when I defined Dtos in the Business Layer. SaveProductDto reference cannot be found.
public class ProductService : IProductService
{
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;
public ProductService(IUnitOfWork unitOfWork, IMapper mapper)
{
_unitOfWork = unitOfWork;
_mapper= mapper;
}
public async Task<Product> AddProduct(SaveProductDto saveProductResource)
{
var newProduct = _mapper.Map<SaveProductDto, Product>(saveProductResource);
await _unitOfWork.Products.AddAsync(newProduct);
await _unitOfWork.CommitAsync();
return newProduct;
}
}
I can't write SaveProductDto here:
public interface IProductService
{
Task<Product> AddProduct(SaveProductDto saveProductResource);
}
ProductService is in the Business Layer, IProductService is in the Core Layer as I explain before. How can I give reference to SaveProductDto in the Core Layer?
Update: Title was changed
question from:
https://stackoverflow.com/questions/65622969/cant-give-dto-reference-to-service-interface 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…