Code Monkey home page Code Monkey logo

Comments (1)

ardalis avatar ardalis commented on July 25, 2024 4

I sometimes find value in using application services. My definition of application services is that they are services specific to the application, and usually that means they're tied closely to the UI. I don't always, or even often, add an application service "layer" because most of the time the UI can interact directly with the domain layer via repositories (to fetch and store entities), entities, and domain services. However, sometimes the UI needs to get data in a particular format that isn't closely mapped to the domain model. In this case, controllers or other UI classes can become bloated with mapping logic and calls to multiple repositories as they try to convert one model to another. This is where application services can be a big help, as they can hide away repositories and the domain layer from the UI layer, and perform any mapping between domain entities and UI-level DTOs or ViewModels, etc.

I do recommend, when possible, that a given class only work with a single abstraction level in terms of its dependencies (i.e. what's being injected via its constructor). It's not a strict rule, but if you can, try to have your services work only with repositories or other services, but not both. Same for controllers. If you're working one level above the repository abstraction level, that's different than if you're working one level above a services abstraction level. When you have mix, it's often a good idea to roll more of the low-level logic up into services so you can eliminate low-level dependencies on repositories, etc.

from cleanarchitecture.

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.