-1

Description

I'm working with a almost 40 year old project with a lot of legacy code. Over the years multiple databases where added. Now I am converting it step by step to the hexagonal architecture with ports and adapters.

Until now I always created 1 adapter per database. But doing so with this code will give me a representation of my databasestructure in my domain (which I don't want).

Example

If I have a Product object in my domain that can look like this:

public class product()
{
public decimal Price {get; set;}
public string Description {get; set;}
public string Name {get; set;}

}

In this scenario it is possible that the price comes from database 1, the description form database 2 and the name from database 3. All linked by a unique code.

Question

How would I do this in the hexagonal architecture? Should I:

  • make 1 productAdapter with multiple repositories (1 for every database)

  • make an adapter for every database and merge everything in my domain (which gives my domain code that is related to my databasestructure)

  • make an adapter for every database and a productAdapter that calls the database adapters?

I hope the description, example and question make sense

Marc van Nieuwenhuijzen
  • 1,415
  • 1
  • 14
  • 20

1 Answers1

1

First of all you should define in your app the port for persisting the product. To do it, you should ask to yourself, from the app point of view:

Does it matter in my app, for solving the problem it is trying to solve, whether the concepts within the product are stored in multiple datastores or just in one?

  • If it matters, you should define 3 ports (one for each datastore). You would merge the data in your app. Since for your app is important that the concepts are stored in different places, your app knows it, it is part of your app.

  • If it doesn't matter, you should define just one port to abstract persistence. And define one adapter for the port. The adapter would access the database it needs depending on the property (price, description, name) you are retrieving. I wouldn't abstract the access to these databases in the adapter creating 3 more adapters. I would access the 3 dbs directly from the product adapter. But it's up to you.

choquero70
  • 3,332
  • 2
  • 24
  • 40