2
I have a project organized as follows:
1. Web (ASP.NET MVC)
2. Application
3. Domain
4. Infra.Data
5. Infra.Log (NLog)
6. Infra.IoC
The project references are as follows:
- Web --> Application
- Web --> Domain
- Application --> Domain
- Infra.Data --> Domain
- Infra.Log --> Application
- Web --> Infra.IoC
I created a log interface in the Application layer and its implementation in the Infra.log. E layer, through injection dependency, I use it in the Web layer and Application. But you can’t use the service in the other layers due to the reference between the projects.
I don’t want to "mess up" the projects with unnecessary references, because the DDD recommends a certain order in the references. For example, the Infra.Data layer cannot reference the Application. But I want all layers to have access to the log service.
- Is there any pattern to solve this?
- And how to do with the Domain layer that you can’t reference nobody?
Why does the Application layer have the interface? The right one would be that staying in Domain.
– Leonel Sanches da Silva
Hi Gypsy, it is because, from what I understand, the application is responsible for coordinating the project, such as: knowing when to call the bank operations, know when to send an email, call a business rule, etc. But then the domain is who should create the interface? Because from what I understand as well, the domain should only be responsible for the business rules.
– Raphael
Create in the Crosscutting layer (inside the Infra)... You can centralize a Library only content Logs logic (both for your Application and for other layers if you wish)... I do so.
– Wilson Santos
Here begin the infinite problems of the DDD approach upon MVC. Note that without using all this stratification, which does not make your project better, it is possible implement a much simpler log system using Actionfilters. But to answer you, yes, the interface is in Domain, because Domain not only models the domain and business rules, but also holds the starting point of the whole system.
– Leonel Sanches da Silva
Architecture serves its purpose as a programmer, and not the other way around; as Gypsy said, perhaps it would be better to implement the simple. Implemented the simple, maybe(yes, maybe) you implement something more sophisticated. Log, as Wilson commented, seems to me something of "orthogonal concerns", IE, theoretically should cover the entire application.
– Marco Aurelio
The best concept for your scenario is cross-Utting ("cross-sectional"). Best information: https://answall.com/questions/82976/oque-%C3%A9-cross-Cutting-e-qual-sua-rela%C3%A7%C3%A3o-com-Aspect-oriented-Programming-aop
– Luiz Miranda de Assis