Skip to content

DDD sample

xhafan edited this page Dec 17, 2018 · 28 revisions

Let's see how to model a simplified cargo insurance policy management system using CoreDdd. The insured cargo will be carried on ships and trucks, and there can be many ships and trucks insured within one policy. There will be following aggregate root domain entities (=aggregate roots):

There will be following non-aggregate root domain entities (=entities):

The policy will have a collection of policy items. CargoPolicyItem will be derived from PolicyItem, and ShipCargoPolicyItem and TruckCargoPolicyItem will be derived from CargoPolicyItem. This model will allow Policy to support not just a cargo insurance business, but other types of insurance businesses as well, for instance a car or a van insurance support could be added by deriving VehiclePolicyItem from PolicyItem, and deriving CarPolicyItem and VanPolicyItem from VehiclePolicyItem.

There will be several commands to manage the system:

The hypothetical application would have several screens to create ships, trucks and policy holders, sending respective commands, and a screen to create a policy, and screens to add ships and trucks to the policy, again sending respective commands. These screens will be populated by data queried over persisted entities - ships, trucks, policy holders and policies. There might be following queries in the system:

The DDD sample source code is available here. It uses couple of controller classes (similar to MVC/Web API controllers) (ShipController, PolicyHolderController, PolicyController) to manage ships, policy holders and policies. It first persists entities via aforementioned controllers which use commands to create or update aggregate root domain entities, and then queries data over the persisted entities.

You can’t perform that action at this time.