CommandHandler - How to instantiate new aggregate with parameterized constructor #901
-
ContextWe have a Command that creates a new aggregate. Examplepublic class CreateMyAggregateCommand : Command<MyAggregate, MyAggregateId, IExecutionResult>
{
public CreateMyAggregateCommand (MyAggregateId id) : base(id)
{
}
}
public class CreateMyAggregateCommandHandler : CommandHandler<MyAggregate, MyAggregateId, IExecutionResult, CompleteProductUpdateCommand>
{
public override Task<IExecutionResult> ExecuteCommandAsync(MyAggregate aggregate, CreateMyAggregateCommand command, CancellationToken cancellationToken)
{
// Here the aggregate instance is constructed using the default constructor.
return Task.FromResult(executionResult);
}
} Questions
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Since you really don't know if the aggregate is already created at the time or it will be created by some competing thread I don't think doing it in the command handler is a good idea. Any information you would want to pass to the aggregate could as easily be passed via any methods and if you want some special factory for your aggregates, create a custom implementation for |
Beta Was this translation helpful? Give feedback.
Since you really don't know if the aggregate is already created at the time or it will be created by some competing thread I don't think doing it in the command handler is a good idea. Any information you would want to pass to the aggregate could as easily be passed via any methods and if you want some special factory for your aggregates, create a custom implementation for
IAggregateFactory