public void Execute(CompositeCommanding.ICompositeCommand compositeCommand) { Contract.Requires <ArgumentNullException>(compositeCommand != null, "Composite Command is null"); Contract.Requires <ArgumentNullException>(compositeCommand.Commands != null, "Composite Command should have atleast one command"); var unitOfWork = NcqrsEnvironment.GetFromWindsor <IUnitOfWorkContext>(); foreach (var command in compositeCommand.Commands) { Execute(command); } unitOfWork.Accept(); unitOfWork.Dispose(); }
/// <summary> /// Constructor, initializes a new instance of <see cref="MappedCommandToAggregateRootMethod<TCommand, TAggRoot>"/>. /// </summary> /// <param name="getidfromcommandfunc">The method responsible for retrieving the id of the aggregateroot from the command.</param> /// <remarks>Marked as internal because the construction is only allowed in the framework.</remarks> internal MappedCommandToAggregateRootMethod(Func <TCommand, Guid> getidfromcommandfunc) { _getidfromcommandfunc = getidfromcommandfunc; // default get aggregateroot code //var factory = NcqrsEnvironment.Get<IUnitOfWorkFactory>(); //using (var work = factory.CreateUnitOfWork()) //{ var work = NcqrsEnvironment.GetFromWindsor <IUnitOfWorkContext>(); _aggregaterootfetchfunc = (guid) => work.GetById <TAggRoot>(guid); // work.Accept(); //} }
public void Execute(TCommand command) { //using (var work = _uowFactory.CreateUnitOfWork()) //{ // var id = _getId(command); // var aggRoot = work.GetById<TAggregateRoot>(id); // _action(aggRoot, command); // work.Accept(); //} var id = _getId(command); var work = NcqrsEnvironment.GetFromWindsor <IUnitOfWorkContext>(); var aggRoot = work.GetById <TAggregateRoot>(id); _action(aggRoot, command); }