Skip to content

Instantly share code, notes, and snippets.

@rvlieshout
Created June 1, 2011 07:09
Show Gist options
  • Save rvlieshout/1001916 to your computer and use it in GitHub Desktop.
Save rvlieshout/1001916 to your computer and use it in GitHub Desktop.
MappedCommandToAggregateRootMethodOrConstructor Execute adjustment?
/// <summary>
/// Executes the command.
/// </summary>
/// <param name="command">The command to execute.</param>
/// <returns>The aggregateroot of type <typeparamref name="TAggRoot"/> on which we executed the command.</returns>
void ICommandExecutor<TCommand>.Execute(TCommand command)
{
var factory = NcqrsEnvironment.Get<IUnitOfWorkFactory>();
using (var work = factory.CreateUnitOfWork(command.CommandIdentifier))
{
var aggregateroot = _aggregaterootfetchfunc(_getidfromcommandfunc(command), command.KnownVersion);
if (aggregateroot == null)
{
aggregateroot = _aggregaterootcreatorfunc(command);
}
else
{
_mappedmethodforcommandfunc(command, aggregateroot);
}
work.Accept();
}
}
/// <summary>
/// Executes the command.
/// </summary>
/// <param name="command">The command to execute.</param>
/// <returns>The aggregateroot of type <typeparamref name="TAggRoot"/> on which we executed the command.</returns>
void ICommandExecutor<TCommand>.Execute(TCommand command)
{
var factory = NcqrsEnvironment.Get<IUnitOfWorkFactory>();
using (var work = factory.CreateUnitOfWork(command.CommandIdentifier))
{
var aggregateroot = _aggregaterootfetchfunc(_getidfromcommandfunc(command), command.KnownVersion) ?? _aggregaterootcreatorfunc(command);
_mappedmethodforcommandfunc(command, aggregateroot);
work.Accept();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment