0

Can Domain Layer and Application Layer be aware of application state? By application state, I mean the state of the an individual app instance.

If I'm making an food delivery for example, and the user logs in to his account and places an order. Now I'll need to add this order under this currently logged in user.

The part where I'm confused is if the application layers service that has a function to add the ordered item to this users list of ordered items, can know which user is currently logged in, which is going to be an info of an individual app instance.

class MakeOrderService {
    void makeOrder() {
        // Here order is being made assuming this function can get the 
        // id of the currently logged in user without it being passed
        // in as a parameter from the controller where its being called.
    }
}

Thanks.

Yamin Nather
  • 99
  • 1
  • 6

1 Answers1

1

Don't make this separation so strict. In theory many things are separated, but in business reality this is not the case. What are business rules is up to you and your specific domain. I would recommend you to go through different DDD implementations and see how it is done. In your concrete example, if you want to expose information about currently logged user to application layer and if your business has this kind of rule then it is perfectly valid. Ask what does "logged user" means in your domain? Some applications allows public view of current logged users. You could often see sometimes something like

127 users online

or

gooUser816461 is online

Miroslav Trninic
  • 3,327
  • 4
  • 28
  • 51
  • In this business, my understanding of a user is someone who wants to purchase or has purchased a service. A logged user will then be someone who's currently in looking to make a purchase. I'm still not clear as to which approach I'm going to use to use though, and I'm not sure if my thinking of the user is correct. – Yamin Nather Jun 03 '21 at 01:55