Practicing DDD (Domain Driven Design) with Intent Architect
Intent Architect and our standard modules have extensive support for modelling DDD (Domain Driven Design) systems for both anemic and rich domain approaches.
A great introduction and explanation of these concepts is covered in our A Deep Dive into Domain Modeling Webinar.
Rich Domain Support in Intent Architect
Our designers have full support for Rich Domain modelling, in particular:
- You can model Operations (behaviors) on Domain Classes.
- In the Services designer Commands, Queries and Service Operations can be mapped directly to Class Operations.
Rich Domain Modelling Example
In this example we will enable "Private Setters" for our domain entities in our Application, model a Class with a Constructor and Operation in the Domain Designer and then in the Services Designer model CRUD Commands and Queries for interacting with our domain entity.
This example assumes you are using an already created Application or you've created a new Application with the "Clean Architecture .NET" application template:
Enabling "private setters"
In order to make it impossible to anemically update domain entities, you can enable the private setters option which makes all domain entities have private
setters as opposed to the default of them being public
.
Go to the Settings of the Application:
Under the Domain Settings section, enable Ensure Private Property Setters and press the Save Changes button.
Create a domain entity
In the Domain designer, create a Customer
entity and add a Name
attribute onto it:
Right-click the Customer
and select the Add Constructor option:
Right-click the Constructor and select the Map Constructor... option:
Select the Name
Attribute and then press the DONE button:
With the constructor created and mapped, you can run the Software Factory and observe the following happening in the Customer.cs
file:
A public
constructor has been created and because we mapped the Name
, it has automatically created a parameter which sets the property.
Also note that a protected
constructor has been created so that Entity Framework is still able to re-hydrate entities it reads from your database.
Similarly to creating the constructor, we will use the Add Operation context menu option:
We'll name it Update
and then use the Map Operation... context menu option:
Again, just select the Name
attribute and press DONE:
When running the Software Factory, observe that it adds a method to the Customer
:
Create CQRS CRUD Operations
In the Services designer, right-click the Services Package and select the Create CQRS Operations option:
Observe that the CreateCustomerCommand
is mapping to the constructor while the UpdateCustomerCommand
is mapped to the Update
operation:
To see the details of a mapping, we can right-click it and choose the appropriate menu option, for example for an [update] we can select the Map Entity Update option:
Observe how the Command is mapped to the Update
Operation while the Name
field is mapped to its parameter:
And when the Software Factory is run you will see that the generated implementation is passing the field's value to the method:
Conclusion
We have now created Rich Domain behaviors on our Domain entity and mapped our services to interact with them.