Am I breaking some Onion Architecture rule?
https://softwareengineering.stackexchange.com/questions/384220
-
17-02-2021 - |
Pergunta
Based on the project structure below i will have some questions
- Domain Layer
1) MyApp.Domain.Entities (DLL)
Product.cs
PagedResult.cs
Referentes
No References
2) MyApp.Domain.Interfaces (DLL)
IUnitOfWork.cs
IProductRepository.cs
Referentes
MyApp.Domain.Entities
3) MyApp.Domain.Common.Interfaces (DLL)
IClock.cs
ICryptography.cs
ILogging.cs
Referentes
No References
- Infrastructure Layer
1) MyApp.Infrastructure.Logging
Will implement the interface ILogging
Referentes
MyApp.Domain.Common.Interfaces
2) MyApp.Infrastructure.Cryptography
Will implement the interface ICryptography
Referentes
MyApp.Domain.Common.Interfaces
4) MyApp.Infrastructure.Data
Will implement the interface IUnitOfWork.cs e IProductRepository.cs
Referentes
MyApp.Domain.Entities
MyApp.Domain.Interfaces
------------------------------ Questions ---------------------------------
A) In my Domain Layer I have MyApp.Domain.Common.Interfaces that will keep interfaces that can be used for all project, this interfaces will represent common elements that whole project can use and will be implemented at Infrastructure Layer.
Am I breaking some Onion Architecture rule having it in my Domain Layer?
Solução
I had the same problem with my app and from my investigation, it seems that most people think that this is a bad idea:
- When Entities make use of Repositories, ie: here
- When Entities make use of Services, this could be avoided by simple refactors, ie: here
In your case, it seems that the IClock and ICryptography is part of the delivery mechanism, not a domain and therefore they should live in the infrastructure layer. It is not clear why your Entities should depend on these. If they do not depend on that infrastructure then you shouldn't keep it in the Domain layer even if this is a common code for all project.
As for ILogging you can solve it by logging domain events produced by your Entities. This way the logging can be a part of a Repository that lives in the infrastructure layer. See here and here