Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
113 views
Welcome To Ask or Share your Answers For Others

1 Answer

Hope the below helps. It is referenced from https://aspnetboilerplate.com/Pages/Documents/NLayer-Architecture

This also provides guidance on how to build n-tier architecture https://aspnetboilerplate.com/Pages/Documents/Introduction

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...