Where to store shared services?

In a domain driven approach. Where to store shared services?

For example. Sometimes we may need common functions like getcountrylist, getstatelist, getcitylist (or some other data from the MASTER tables) to show the dropdown on different pages / UI modules. Suppose this data is present in the database, then we should have these functions.

  • Can I keep these functions inside the /Common/CommonServices.php domain (I mean, what's good inside the domain?) (Or)

    Can I keep these functions inside Infra / Common / CommonServices.php (in this case I need to connect to the dao file directly from the Infraservice layer, which I think is wrong?)

  • What is the correct name / suggested name for the file that contains these common functions. (CommonServices.php (or) CommonHelper.php (or) CommonUtils.php (or) MetadataService.php (or) whatever your suggestions)

+3


source to share


2 answers


If you really want the same data in different bounded contexts, and you are fetching it with the same repository, then there is something in DDD called SHARED KERNEL. SHARED KERNEL is where you put things that overlap in multiple bounded contexts, quote from DDD Quick:

The purpose of the Shared Kernel is to reduce duplication, but still keep two separate
contexts. Development on a Shared Kernel needs a lot of care. Both teams may modify
the kernelcode, and they have to integrate the changes.
If the teams useseparate copies of the kernel code, they have to merge the codeas soon
as possible, at least weekly. A test suite should be inplace, so every change done to 
the kernel to be tested right away. Any change of the kernel should be communicated
to another team, and the teams should be informed, making them aware of the new
functionality.

      



Anyway, if your SHARED KERNEL gets too big, it could be a problem with your modeling. Try to keep SHARED KERNEL as small as possible.

+4


source


Behavior is data bound, so I would put it in a dedicated repository or fax Read Model. You can also use a domain service, but service is an overloaded term and does not convey the data access aspect IMO.

If you take the CQRS approach, I would recommend placing it in a separate reader. Otherwise, you can keep the domain-level interface and implementation in the infrastructure just like in other repositories.



(edit) to make things clearer, this facade can be called directly by controllers as it is just read-only and not manipulating aggregates that might have to go through the application layer services that manage the applicative transaction.

0


source







All Articles