🔏
Azure Serverless Quickstart
  • Introduction
  • Initial Setup
    • Workstation Installs
    • Codebase
      • Directory Structure
      • User Interface Project
        • Configuring StoryBook
        • Configure Tailwind
        • Configure Craco
        • -Architectural Decision Log
      • Data Access Project
        • DDD
      • Untitled
      • Full Stack Debugging
      • Creating GitHub Project
    • Infrastructure
      • Configure Session Behavior
      • Create AAD Tenant
      • Resource Group
      • Create AAD B2C Instance
        • Identity Experience Framework
        • Configure Session Behavior
      • Storage Account & CDN
        • CDN Rules
        • Configure Azure BLOB Storage
      • App Insights
        • Create AppInsight Account
        • Apollo GraphQL App Insights Configuration
      • CosmosDB
      • Twilio SendGrid
      • KeyVault
      • Function
      • Function App Settings
      • Front Door
      • DevOps
      • Optional Items
        • Azure Data Factory
      • Azure Event Hub
    • CICD and Source Control
      • Azure DevOps
      • SonarCloud
        • Incorporate into Yaml
      • Chromatic
      • User Interface YAML
      • CICD for Data Access
        • Create Pipeline
        • Data Access YAML
  • Application Structure
    • Connect Apollo
      • Apollo Overview
      • Create Apollo Component
    • MongoDB Integration
      • Mappings
      • Directory Structure
      • Apollo Connection
      • Models
      • Queries Mutations and Subscriptions
      • Caching Reponses
    • Integrating GraphQL Tools
      • GraphQL Code Generator
    • Feature Flags
      • Flag Structure & Storage
      • Website Integration
      • Apollo Integration
      • Tips and Techniques
      • Alternative Approaches
    • React Router
    • Adding Authentication
      • Create AAD Applications
      • Configure AAD For External Identities
      • Adding MSAL And React
      • Add MSAL to the build
      • Add MSAL to ApolloClient
      • Add MSAL to ApolloServer
    • Ant Design
    • Jest Tests
  • Azure Active Directory Business-to-Consumer (AD B2C)
    • Introduction
    • How to navigate through AD B2C documentation
    • Localization
    • Abbreviations
    • Azure AD B2C Extension
  • Cognitive Search
  • Cost Analysis
  • Technical Architecture
    • Identity and Access Control
  • Adding Functionality
    • Google Analytics
      • Create Analytics
    • DAPR
      • DAPR setup
      • DAPR Services (ignore for now)
        • Identity
  • Patterns and Practices
    • Idempotent Messages
    • Pathways
    • DDD
      • Initial Setup
        • Aggregate Root
        • Entity
        • Value Object
      • Field Types
        • Primitive Types
        • Non-Primitive Types
          • Types.DocumentArray
          • PopulatedDoc
          • Custom Types
      • Example Walkthrough
  • Open Items
    • Issue Tracking
  • Helpful Resources
  • DDD
    • Page 1
  • Experimental
    • StaticWebApp
    • Azure Maps
Powered by GitBook
On this page

Was this helpful?

  1. Patterns and Practices
  2. DDD

Example Walkthrough

Goes through an illustrated walkthrough of setting up the Physician domain context

PreviousCustom TypesNextIssue Tracking

Last updated 2 years ago

Was this helpful?

Open up the cosmos db model file you are going to work on found in the /infrastructure/data-sources/cosmos-db/models/ directory. In this example, we are working with physician.ts model

In /domain/contexts/ directory, you will find various directories named with different contexts

Find the folder for domain object you are working on and create a file named after the interface which extends Base in the cosmos db schema

In this example, we look under /domain/contexts/ for the physician folder

We create the stub domain context file physician.ts in /domain/contexts/physician/

Copy the fields from cosmos db model for Physician into PhysicianProps on domain side

The first non-primitive type in this example is the licenses field on line 74 in the Cosmos DB model On domain props side, the licenses field should be a readonly PropArray of PhysicianLicenseProps

Now we have to make the domain context file for PhysicianLicense. Look for the interface in the cosmos db model for physician

In this example, PhysicianLicense interface extends SubdocumentBase

Created this physician-license.ts domain context file in /domain/contexts/physician/

Now you fill out the props for the PhysicianLicense using the interface on the cosmos db side

The type of the field is PhysicianRegulatoryAuthorityProps and it's readonly

Also need a setPhysicianRegulatoryAuthorityRef field below it, which is a method that takes a PhysicianRegulatoryAuthorityEntityReference as an argument

Note: You only need this setRef field if in the cosmos db schema you see type: ObjectId and ref, otherwise the field is local to the aggregate root

Now fill out the rest of the fields from the PhysicianLicense interface in the cosmos db model

Next step is the entity reference interface.

Every field that refers to another props or if the field is a setRef method needs to be omitted

The names of the field are passed as a union of strings. Refer to the image below. If the props only contains primitive fields, then you can leave the entity reference as it is.

The last step is the class for the domain object

Since the cosmos db model is a SubdocumentBase, this class should extend Entity

Need to create getters for every field and requestSet methods for all the primitive and PopulatedDoc type fields

For fields that are props of another domain context, we pass the props field into that domain context's constructor along with the context.

For the requestSet of those fields, we use the setRef field we created in the props and pass in that domain context's entity reference.

This domain context file for PhysicianLicense is now complete. We can go back to physician.ts and import it.

Also make sure the field is readonly, just like we do for any props type field.

Since this is a PropsArray, we don’t need a setRef field for licenses.

Don't forget to omit licenses from the entity reference interface.

For PropsArray fields, we use a ReadonlyArray for the entity reference.

Continue going through the rest of the Physician interface fields in cosmos db model

In this example, PhysicianSystemTagProperties is a NestedPath. Therefore, we have to create a physician-system-tag-properties.ts domain context file

Also, Value Objects don’t use the props extends generic structure that you see for Aggregate Root or Entity extended-classes.

Now you just have to fill out the props just as you did for the other domain context files

For this example, there is only one primitive field so it's a relatively simple domain object

Now you should have seen every scenario you might encounter when building up the domain context files.

You should be able to translate any cosmos db model into the domain layer.

An interface that extends Base means the domain object is an

Refer to the documentation about what to do for primitive and non-primitive type fields

so PhysicianLicenseProps extend EntityProps and the PhysicianLicense class extends

The first field in our case is type reference to another aggregate root so we have to treat it differently than a primitive field.

In the cosmos db physician interface, it says licenses is a so we need to wrap PhysicianLicenseProps in a PropsArray for the domain props field type.

You may reach a field which refers to a defined locally in the cosmos db model

Since PhysicianSystemTagProperties is a NestedPath, the props interface should extend ValueObjectProps and the class should extend .

Aggregate Root
Field Types
Entity
PopulatedDoc
Types.DocumentArray
Custom Type
Value Object
Cosmos DB Model (/infrastructure/data-sources/cosmos-db/models/physician.ts)
Physician Domain Context file (/domain/contexts/physician/physician.ts)
Domain Props on left, Cosmos DB Model on right
PhysicianLicense Cosmos Model (/infrastructure/data-sources/cosmos-db/models/physician.ts)
Physician License Domain Context file (/domain/contexts/physician/physician-license.ts)
Physician License Domain Props (/domain/contexts/physician/physician-license.ts)
Physician License Domain Props (/domain/contexts/physician/physician-license.ts)
Physician License Entity Reference (/domain/contexts/physician/physician-license.ts)
Physician License Domain Class (/domain/contexts/physician/physician-license.ts)
Physician Domain Context File (/domain/contexts/physician/physician.ts)
Physician System Tag Properties Domain Context file (/domain/contexts/physician/physician-system-tag-properties.ts)
Physician System Tag Properties Domain Context file (/domain/contexts/physician/physician-system-tag-properties.ts)