-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Using Infrastructure.Logging in Application Core #52
Comments
I don't see any issues with how it is implemented. All ApplicationCore, Web, and even Infrastructure needs to know about is IAppLogger. If you need to log in ApplicationCore, you'd inject IAppLogger into your classes. They shouldn't know or care how it is implemented in Infrastructure. |
Correct, what @yarrgh said. |
So, is it OK to have a Run time dependency to ApplicationCore from Infrastructure? |
Yes, certainly. This follows the Dependency Inversion Principle. Concrete implementations (in Infrastructure) should depend on abstractions (interfaces in ApplicationCore), not vice versa. |
Infrastructure has a compile time dependency of Application Core, and Application Core has a run time dependency of Infrastructure. Runtime dependency is mentioned in the ebook, but Application Core seems to be isolated from Web App and Infrastructure dependencies. Sort of confused, whether we should have that run time dependency at all to the Application Core. |
Exactly.
This is by design. The fewer dependencies the ApplicationCore project has, the easier it is to test.
If you didn't have any runtime dependency, that would imply that the only thing in ApplicationCore was abstractions (e.g. interfaces, abstract base classes). There would be 0 lines of actual executable code. Thus, nothing to test. You need to have your business/domain logic live somewhere. If there were no executable code in ApplicationCore, then your domain logic would either be in Infrastructure (highly coupled, harder to test) or in UI (also not the right place for it). |
The eBook has some references for more reading on Onion Architecture, Clean Architecture. You might benefit from reading those. If you have Pluralsight, I suggest checking out my courses on N-Tier C# apps, Domain-Driven Design Fundamentals, and SOLID Principles of OOP. I can send you a 30-day free pass if you need one. HTH. |
Thanks Steve. I do have a Pluralsight subscription, I will checkout those courses. I am keen on DDD and Clean architecture, was trying to construct something that abide by the Clean DDD Architecture. @yarrgh Exactly, core principle is to make the dependencies loose and flexible. Thanks. |
Do I understand correctly that if I have IEmailSender, IPushNotificationSender and IUriComposer interfaces in ApplicationCore then EmailSender and PushNotificationSender implementations should be in Infrastructure project (since they depend on 3rd party libs) and UriComposer should be in ApplicationCore (does not depend on libs)? Or is it because EmailSender and PushNotificationSender communicate with external services? |
The rules I follow when using Clean DDD Architecture (as this sample does) are:
Does that help? |
It is clear now. Thanks Steve! |
Implementation of Logging is part of the Infrastructure. Application Core will have it's own service implementation, for instance in this project it is UriComposer. There will be logging required in ApplicationCore, since it is not just the domain entities. How do I make use of Logger in ApplicationCore? Shouldn't this Logger be shared independent project out of infra and core?
The text was updated successfully, but these errors were encountered: