I know there is a lot of similar information online and also on stackoverflow, but I'm still not sure where to put the logic of persistence into my project. I don't yet use any ORM, IoC and UnitOfWork concepts (too much new stuff for a beginner in the ddd world).
I see two options for my Order model:
- Inside the Domain assembly there is an
Order
class and anIOrderRepository
interface.Order
class has a private instance of theIOrderRepository
which is passed in the constructor. Order class has a publicInsert
method, which calls theIOrderRepository.Insert
method. The actual implementetion of the repository is inOrderRepository
class of the Infrastructure layer. The Service layer would contain anOrderService
class which instantiates my model with the appropriate repository and then callsOrder.Insert()
. The bad: we have to inject an interface (or multiple instances) of the repository to the model class, persistence logic is inside the model. The good: sometimes something has to be done before or after the insert method is called and this could nicely fit into theInsert
method of theOrder
class, for example raising domain events or whatever. - In the
Model
assembly there is onlyOrder
class. The Service layer creates newOrder
and newOrderRepository
and executesorderRepository.Insert(order)
.
Could you please explain which concept is better in simple words (explain like I'm Five).