Search Results for

    Show / Hide Table of Contents

    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:

    Clean Architect .NET Application Template selection

    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:

    Application Settings context menu option

    Under the Domain Settings section, enable Ensure Private Property Setters and press the Save Changes button.

    Domain Settings

    Create a domain entity

    In the Domain designer, create a Customer entity and add a Name attribute onto it:

    Customer entity with Name attribute

    Right-click the Customer and select the Add Constructor option:

    The Add Constructor context menu option

    Right-click the Constructor and select the Map Constructor... option:

    The Map Constructor context menu option

    Select the Name Attribute and then press the DONE button:

    The Map Constructor screen

    With the constructor created and mapped, you can run the Software Factory and observe the following happening in the Customer.cs file:

    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:

    The Add Operation context menu option

    We'll name it Update and then use the Map Operation... context menu option:

    The Map Operation context menu option

    Again, just select the Name attribute and press DONE:

    The Map Operation dialogue

    When running the Software Factory, observe that it adds a method to the Customer:

    Update method being added to the Customer

    Create CQRS CRUD Operations

    In the Services designer, right-click the Services Package and select the Create CQRS Operations option:

    The Create CQRS Operations context menu option

    Observe that the CreateCustomerCommand is mapping to the constructor while the UpdateCustomerCommand is mapped to the Update operation:

    Customer diagram showing commands, queries and mappings

    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:

    Map Entity Update context menu option

    Observe how the Command is mapped to the Update Operation while the Name field is mapped to its parameter:

    Entity Update Mapping screen

    And when the Software Factory is run you will see that the generated implementation is passing the field's value to the method:

    UpdateCustomerCommandHandler.cs file

    Conclusion

    We have now created Rich Domain behaviors on our Domain entity and mapped our services to interact with them.

    • Edit this page
    ☀
    ☾
    In this article
    Back to top Copyright © 2017-, Intent Software Pte Ltd.