1

I am working on my project using ASP.NET Core Web API. I have opted for a clean architecture approach, comprising Core, Infrastructure, Application and Presentation layers.

The entities in my project are Employee (with a foreign key DepartmentId) and Department.

I've read that the repository in the Infrastructure layer should exclusively work with entities. However, I'm facing a challenge: how can I retrieve an Employee along with their DepartmentName?

I am considering using a DTO (Data Transfer Object), but the issue is that DTOs typically reside in the Application layer, not the Core layer.

Could you please provide some solutions on how to achieve this with a more robust architecture?

Thank you so much!

0

2 Answers 2

1

In the Application Layer, which contains business logic and orchestrates data from entities, conversion of Value Objects (VO) is typically handled. So, it's suitable to use DTO in this layer.

AS for the Infrastructure Layer, usually been used in data retravel.

I think you could try to use the DTO in application layer.

Sign up to request clarification or add additional context in comments.

3 Comments

so multiple requests to db?
you could add a cache such as redis to improve that
It will still be slow the first time for that user. And redis cache should not be necessary if we would just not introduce this issue in the first place. I think OP knows we could use redis. But the challenge is to design in a way to keep this separation of concern while still allowing to query both of the values together for performance.
0

I am considering using a DTO , but the issue is that DTOs typically reside in the Application layer, not the Core layer.

I am assuming you meant to say "not the infrastructure layer".

You can keep the repository repository interface in the application layer and provide implementation in the infrastructure layer. And I don't think there is anything wrong with having DTOs in the infrastructure layer.

You could check this for reference: https://github.com/ardalis/CleanArchitecture/tree/main

3 Comments

But I think the repositoty interface must be in Core layer, so Core layer will have to reference to Dtos in Infrastructure layer ?? I think it's wrong
@BaubauTran well upto you I guess, but how would you do without implementation in the infrastructure layer?
Also are you suggesting that the Adralis template is "wrong"? Can you explain why? @BaubauTran

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.