I've recently watched a few Pluralshigh courses on DDD by Vladimir Khorikov. He was encouraging to create a rich instead of anemic domain models. It all looked very nice in a small test-project, however I still have no idea how to put extensive business logic inside rich domain model.
In rich domain model we are supposed to put domain logic into entities. So let's say we want to model an Employer
who pays the salary the their Employees
. I see Employer as the aggregate root here.
So we add a Employer.PayTo(someEmployeeIdentificator)
method. Business rules for calculating the salary could be very elaborate and depend on things like:
- Employer and Employees countries
- Employment form
- Employee taxation form
- How much did an Employee work last month
- and so much more, you get the point
Potentially, there could be a few dozens of algorithms. Some might even require communication with external services. A perfect case for strategy pattern, but:
- The logic was supposed to be implemented inside the entities
Employees
are hidden inside theEmployer
aggregate root- I cannot use
IOC
to inject stuff into my entities (they are usually created by some ORM). And providing the dependency trees is no fun. - Injecting the some implementations of SalaryCalculator to the
Employer
entity might be a bad idea, as the calculators might not be 'pure'. They might have references to some external resources (e.g. issue tracker)
How would you model it?