Fede
Fede

Reputation: 884

Usage of domain services as data provider to entities and value objects

Let's say I have a domain which purpose is to evaluate financial instruments in a given currency. We can imagine having an abstract instrument class defined as follow:

enter image description here

Then we can have different implementations of the Valuate method. But in all the cases, we need to know the price of the instrument and the FxRate to apply to convert the computed value from the currency of the instrument to the currency given in parameter.

I see different possibilities here:

  1. Instruments hold their Price as property/member and they have a Dictionary of FxRates to perform the convertion
  2. Prices and FxRates are provided by external domain services (ex: PriceProvider, FxRateConverter). And could be injected in the Valuate function as parameters from Application Service.

On my opinion the first solution doesn't seems "right".

In the second cases, I'm not sure if using a Domain Service is the correct way to go, as I read in many blogs that Domain Services should not contains private members and should be simple stateless methods. In this case we will need two domain services, once having the price for each instrument and one with all the FxRates for each currencies we may work with. Eeach service must be instanciated after having retrieved the prices and FxRates from the DB. So implementation of such services will be instanciated from the application service which should only know the interface and not the concrete class of those services.

So, what is on you opinion the correct way to go if we want to respect DDD principles?

Upvotes: 0

Views: 45

Answers (0)

Related Questions