GithubHelp home page GithubHelp logo

Comments (11)

ardalis avatar ardalis commented on May 14, 2024 5

The rules I follow when using Clean DDD Architecture (as this sample does) are:

  1. Minimize dependencies in ApplicationCore; do not depend on anything that depends on infrastructure. So, no references to EF or SendGrid or any other packages that are about out-of-process communication. This keeps ApplicationCore easy to test and easy to depend on without tying the app to a particular infrastructure decision.

  2. Making sure to follow rule 1, if you can move something into ApplicationCore, you probably should. This mostly pertains to Services. If you have a Service that sends emails using direct calls to System.Net or some SendGrid client library, it should probably go in Infrastructure since you don't want those dependencies in ApplicationCore. However, if you have a Service that acts at a slightly higher level of abstraction and it "sends emails" by calling an injected interface like ISendEmail, and performs other logic that has no external dependencies, then this service could certainly live in ApplicationCore (since it has no dependencies on external infrastructure or specific implementation details).

Does that help?

from eshoponweb.

ardalis avatar ardalis commented on May 14, 2024 1

Yes, certainly. This follows the Dependency Inversion Principle. Concrete implementations (in Infrastructure) should depend on abstractions (interfaces in ApplicationCore), not vice versa.

from eshoponweb.

rageshvr avatar rageshvr commented on May 14, 2024 1

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.

from eshoponweb.

trevor-hackett avatar trevor-hackett commented on May 14, 2024

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.

from eshoponweb.

ardalis avatar ardalis commented on May 14, 2024

Correct, what @yarrgh said.

from eshoponweb.

rageshvr avatar rageshvr commented on May 14, 2024

So, is it OK to have a Run time dependency to ApplicationCore from Infrastructure?

from eshoponweb.

ardalis avatar ardalis commented on May 14, 2024

Infrastructure has a compile time dependency of Application Core, and Application Core has a run time dependency of Infrastructure.

Exactly.

Runtime dependency is mentioned in the ebook, but Application Core seems to be isolated from Web App and Infrastructure dependencies.

This is by design. The fewer dependencies the ApplicationCore project has, the easier it is to test.

Sort of confused, whether we should have that run time dependency at all to the Application Core.

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).

from eshoponweb.

ardalis avatar ardalis commented on May 14, 2024

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.

from eshoponweb.

rageshvr avatar rageshvr commented on May 14, 2024

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.

from eshoponweb.

ogix avatar ogix commented on May 14, 2024

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?

from eshoponweb.

ogix avatar ogix commented on May 14, 2024

It is clear now. Thanks Steve!

from eshoponweb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.