I have 2 Aggregate Root: One is the Lessor user, and the other is the Lessee user.

class Lessor extends AggregateRoot {}

class Lessee extends AggregateRoot {}

Each of these Aggregate Roots has a email property, it is a Value Object.

class Email extends ValueObject { }
class Lessor extends AggregateRoot {
    private email: Email

class Lessee extends AggregateRoot {
    private email: Email

I am not sharing an instance of Email, I am sharing the code of Email.

Can I put the Email code in the SharedKernel folder?

  • I didn't want to duplicate the Email code by placing it in theDomain folders of each Aggregate Root.
  • And don't even put the Email code in one of the Aggregate Roots and import it in the other.
  • 2
    You don't need to duplicate code; place it wherever you want - if you have some place that you use to put shared domain code, place it there; DDD doesn't mandate anything organizational at that level of detail. Also, I get the impression that you've read somewhere that DDD mandates folder names and a certain folder structure - it does not. There is a concept of a "shared kernel" in DDD, but it isn't really a folder; rather it's a strategy for coordinating between different teams working on different bounded context. Mar 17, 2020 at 2:25
  • So, if that's what your SharedKernel folder is meant to be, then don't place it there, but maybe make some other shared folder. If you don't really have to coordinate with another team, then maybe rename that folder and place your code there. But ultimately, you (and your team) are free to organize your own code as you see fit. Mar 17, 2020 at 2:25
  • Wonderful! I understood!
    – Cadillac
    Mar 17, 2020 at 21:22


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.