Have been looking at the
6h Greg CQRS vid, and have a very basic question.
In
the vid we see something like this:
public class TransactionalHandler<T> : Handles<T> where T : Message {
private Handles<T> _next;
public TransactionalHandler(Handles<T> next) {
_next = next;
}
public Handle(t cmd) {
using (new UnitOfWork()) {
_next.Handle(cmd);
}
}
}
I realise that writing "using (new UnitOfWork())" could be conceptual - for illustration purposes - but if not, I'd like to know how this works.
How is that UoW implemented, how will the aggregates' events be saved within it? How does wiring look when putting the new instance within "using"?
I'd imagine a UoW look something like this:
public class UnitOfWork
{
private IRepository _repository;
private List<IAggregate> _uncommitted;
public UnitOfWork(IRepository repository)
{
_repository = repository;
_uncommitted = new List<IAggregate>();
}
public void Add(IAggregate aggregate)
{
_uncommitted.Add(aggregate);
}
public void Submit()
{
foreach (var a in _uncommitted)
{
_repository.Save(a);
}
}
}
Thanks