Skip to main content
12 events
when toggle format what by license comment
Aug 9, 2022 at 8:09 vote accept Álvaro García
Aug 8, 2022 at 14:05 comment added Flater @ÁlvaroGarcía: This question is becoming a back and forth on several approaches that go hand in hand with what it is that you're trying to do, but this is not the right format for answering all those questions. I suggest consulting a book or tutorial to help you set up the basics of your framework.
Aug 8, 2022 at 14:04 comment added Flater @ÁlvaroGarcía: The concrete unit of work may exist in the DAL but that does not mean that the domain cannot define its interface so other ancillary layers depend on the domain's interface, not the persistence layer's concrete type.
Aug 8, 2022 at 14:01 comment added Álvaro García Well, I think the unit of work is in the persistence layer, that it has to ensure the data is stored in a coherence way, but the business logic only should to order to save, not how. Perhaps I should to expose that the business logic could have 2 methods, one only with he core business logic and other with the business logic and the order to persist the data.
Aug 8, 2022 at 13:18 comment added Flater @ÁlvaroGarcía: One method to do the work, the other to save the work that has been done. In general, I would recommend a single save action that accounts for all the mutations that took place, as this gives you the benefit of transactional safety. You can look into a unit of work for this as it is the most common pattern to handle transactional commits.
Aug 8, 2022 at 12:01 comment added Álvaro García Or perhaps I could have 2 methods in the domain classes? DoWork() and DoWorkWithPersistance()?
Aug 8, 2022 at 11:48 comment added Álvaro García Then in the second option where domain exposes a public save to allow consumers to decdie when to save. In this case, whold the domain have two public methods, one for Dowork() and another Save() and the cousmer, UI, calls both, Dowrk() and then Save()? So in the UI the consumer can decide when it only wants to run the core business logic and when to save the results?
Aug 8, 2022 at 11:27 comment added Flater @ÁlvaroGarcía: Think of the domain like a monarch who has the power to allow/disallow anything they please. If you let the BLL directly call the DAL's save method, then you are bypassing the domain and preventing it from disallowing this from happening under certain circumstances. To continue the analogy, bypassing the monarch's authority is treason and punishable by death penalty in DDD-land.
Aug 8, 2022 at 11:24 comment added Flater @ÁlvaroGarcía: The domain is able to decide for itself whether it wants to (a) enforce that data will be persisted, no question about it (= private implementation) or (b) allow external consumers to decide to persist the data or not (= exposing its own public save method which links to the persistence save method). By routing this via the domain, it is the domain who decides how things work, which is exactly what DDD tells you to do. But one of those possible decisions can be to give the consumer the ability to indicate a save, if the domain consents to this possibility.
Aug 8, 2022 at 10:43 comment added Álvaro García Well, supose that I have orders and lines and I want to add a new line to an order. The domain validate data, ensure the line can be added and do it. For my first understanding, this is the business logic, and the domain do this work. But for me it is more confuse why the domain has to decide to persist the data or not. It did its job, add the line and ensure a coherence data. Perhaps I want only work in memory, if the domain persists data, I couldn't do that.
Aug 4, 2022 at 18:38 history edited Flater CC BY-SA 4.0
added 799 characters in body
Aug 4, 2022 at 18:28 history answered Flater CC BY-SA 4.0