Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

c# - Can't Give Dto Reference to Service Interface

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...