Migrating from a database centered application to DDD based application

72 views Asked by At

I have a problem that I'm struggling to solve. The problem ist that I want to migrate an existing application into an appliction with a proper domain layer.

The existing application really is just big collection of database queries because all business logic is implemented inside the database with triggers, procedures and functions. All the application does is query some data, manipulate the data in an anemic domain model and store the result back to the database so the database can apply the business logic, validate, etc.

The business logic inside the database really is just to intertwined with everything else to really pull it apart bit by bit.
The only solution I came up with until now is to connect the a completely new domain layer with the existing data access layer with an appropriate adapter. Mainly in the form of domain model <-> database entity converters. But if I do that I can't just use the domain logic of my domain model and store the end results back to the database, because it would violate the implemented business logic and validations inside the database. So any complex transaction must still store back it's intermediate results to the database, hence I'm still stuck with an anemic domain model.

Has somebody got an idea how to tackle this situation and gradually migrate towards a rich domain model?

1

There are 1 answers

0
R.Abbasi On

I had the same problem and I got this solution. I hope this proves useful.

  • Gather all related SP calls in the same interfaces.
  • In our case, it was not possible to move directly from an SP-oriented design to a domain model pattern. So we made it with the transaction-script pattern. For each SP we made an application service method. We translated the SP logic into ORM-made queries and we manipulated data in our methods.
  • Remove each SP after all its related triggers and dependencies are taken care of.
  • After the above steps, you will have an application layer that reflects the SPs exactly.
  • The next step would be refactoring from the transaction script pattern to the domain model pattern.