Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where put a common value object between two bounded contexts?

i'm trying to apply the domain driven design in a little project i want to separate the authentication of rest of the users logic, i'm using a value object for the id (userID) in the beginning i have the userID in the same level(package) of the users but I realize when i separate bounded context for authentication and user, they share a common value object for the userID, so my question is where supose that i have to put the common or share value objects? is correct if i created a packages called commons?

like image 991
Alejandro Mora Avatar asked Jan 30 '23 22:01

Alejandro Mora


2 Answers

It is recommended to not share models between bounded contexts, however, you can share IDs and even simple Value objects (like Money).

The general rule is that you may share anything that is immutable or that changes very infrequently and IDs rarely change structure (here immutability refers to the source code and value immutability).

like image 148
Constantin Galbenu Avatar answered Feb 14 '23 11:02

Constantin Galbenu


Packages called "common" usually refers to reusable concepts that you use in your projects, so that you don't have to code them in every project. There it's usual to put base abstract objects and interfaces, for entities, value objects, etc.

But it's not your case about userId. What you are saying is to put userId in a "shared kernel" model. It is an option, but usually it is not recommended.

From my point of view:

The auth BC has the concepts id,login,password,role,etc.

The user BC has concepts like name,surname,address,age,etc, but it also has to have the id, that it gets from auth BC.

From what I know, you have 2 options:

(1) Authentication BC shares "id" concept explicitly, i.e. it has a shared kernel. So "id" concept would belong to user BC model too.

(2) Authentication BC is a generic BC. So you have to integrate the user BC with the auth BC to get the id from it.

like image 20
choquero70 Avatar answered Feb 14 '23 11:02

choquero70