Custom Types

Describes how to deal with a cosmos db fields of custom types local to that domain object

Cosmos DB Model

/infrastructure/data-sources/cosmos-db/models/minicex.ts
review?: MinicexReview;

Domain Props

/domain/contexts/new-application/minicex.ts
readonly review: MinicexReviewProps;
  • Note: Custom types local to aggregate root like MinicexReview do not need a setRef method

  • Only need setRef for PopulatedDoc field types which refer to other aggregate roots not local to the domain object

Domain Entity Reference

/domain/contexts/new-application/minicex.ts
export interface MinicexEntityReference 
extends Readonly<
    Omit<
        MinicexProps,
        "review"
        >
    > {
    readonly review: MinicexReviewEntityReference;
}

Domain Class

Getter

/domain/contexts/new-application/minicex.ts
get review(): MinicexReviewEntityReference {
    return new MinicexReview(this.props.review, this.context);
}

Setter

  • Note: only need setter method if you have a setRef method for that field

  • Otherwise setting the props of the custom type is handled in that custom type's domain class

Domain Adapter

Getter

/domain/infrastrucure/persistence/minicex.domain-adapter.ts
get review()
    if (this.doc.review) {
        return new MinicexReviewDomainAdapter(this.doc.review);
    }
}

Setter

  • Note: no setter needed for custom types local to the aggregate root

Last updated