0

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?

Fede
  • 804
  • 1
  • 10
  • 21
  • You seem to have confused service design with object oriented design. A user of the service expects to get the price of instruments in a given currency from a service. So, there should be only one service, and whether it references two different tables to do that is the service logic. – Salil Nov 23 '22 at 06:51
  • No, I probably mis-explained myself. I can receive a command with a list of instrument symbols, which I want to evaluate. So I want to evaluate all of them not only one. In this case, should I iterate and request the price and fxrate for all of them(many requests to db). Should all the fxrates and price previously uploaded in memory into a PriceProvider or FxRateConverted domain services which I inject to the valuation method. Or should first save instrument into my relational database to retrieve them with their price and all fxrates to perform valuation indenpendently. – Fede Nov 23 '22 at 08:22
  • So is it fine to preupload all the information( in this case FXRates by example) only once and hold them in a service which is used by each domain object to perform the convertion (Ex: FxRateProvider) or should each domain object contain the FXRates and perform the conversion themself without using any external service. – Fede Nov 23 '22 at 08:29
  • I still think we are talking about one service and how it is computing values of instruments in Fx rates. – Salil Nov 23 '22 at 20:43
  • Well, this doesn't answer the question in anycase. – Fede Nov 24 '22 at 09:14

0 Answers0