I’m a bit confused about handling long-running processes with CQRS and DDD. Recently, a business requirement emerged to change prices using a CSV file.
I would like to design this process knowing that new requests of the same type (import and edit via CSV file) will come in.
it will always involve transforming the file into individual commands and launching them one by one. Additionally, I would like to track the progress status to provide feedback to the user, but perhaps this can be achieved by listening to various events and updating the read side.
Currently, I have a SetItemPriceCommand
that sets the price of an aggregate root ItemPrice
. My idea is to reuse this command to change the prices of items specified in the file.
In practice, after parsing and validating the file, the records are saved and associated with an aggregate root of type PricesImportRequest
:
public class PricesImportRequest : AggregateRoot
{
public int RequestId { get; private set; }
public ReadonlyCollection<PricesImportRequestRecord> Records { get ... }
public ReadonlyCollection<PricesImportRequestRecordError> BadRecords { get ... }
}
When this aggregate root is created, an event PricesImportRequestCreated
is raised. A related event handler then executes a command to create a new aggregate root representing the import operation:
public class PricesImport : AggregateRoot
{
public int PriceImportId { get; private set; }
public ReadonlyCollection<PriceImportItem> Items { get ... }
public PriceImportStatus {get; private set ... }
}
At this point the final step is looping over the Items, map them to the SetItemPriceCommand
payload and run the command, but who is the actor that should be do that ? A command handler that runs commands ?
I know there is a concept of Saga or Process Manager, but I can’t seem to find a sample implementation with .NET.
Please, don’t come down on me if I said something wrong, I’m new to DDD and CQRS and my project is already set up this way.