2

I have some middleware code which fetches a list of products from an external api. I am modelling the response and returning that response to clients of my code.

Any clients of my code do not care about specifics on individual products returned: they simply want the collection of products.

How would that be modelled using ddd?

Each product property a value object, a product an entity and a repository to contain all of the products?

Marty Wallace
  • 34,046
  • 53
  • 137
  • 200

3 Answers3

0

Why not use CQRS (https://learn.microsoft.com/en-us/azure/architecture/patterns/cqrs).

Separate your models into read and write models. In your case read models will do. Make they POCOs. On the read side we do not need to use DDD tactical modeling tools.

For more info visit the link i provided.

aspxsushil
  • 514
  • 1
  • 5
  • 16
0

I think you are almost there, your middleware(external api) could be a repository, by having find methods, and returning Product models.

It is recommended a repository be an interface (e.g. ProductRepository) for making the code more testable. You could have simple implementation for tests(e.g. ProductRepositoryTestImpl) and main implementation for middleware communication (e.g. ProductRepostioryImpl).

For packaging, I prefer this:

domain
      \model
            \product
                    |Product
                    |ProductRepository
infrastructure
              \persistence
                          \YOUR_EXTERNAL_API_NAME
                                                 |ProductRepositoryImp
                          \eclipselink
...
   \test
        \...
            |ProductRepositoryTestImpl
SidMorad
  • 954
  • 12
  • 19
0

You should see the external api like an external bounded context. Your local bounded context will use an anti-corruption layer that translate terms from remote to local bounded context. So, your code is in fact an anti-corruption layer.

Now, should you persist those products as entities or value objects? This depends on your local usage. Do you modify those products or not. If you don't modify them then they are Value objects.

In any case you probably will have to use a repository to persist/retreive the products.

Constantin Galbenu
  • 16,951
  • 3
  • 38
  • 54