/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { Contract.Ensures(IsDisposed == true); if (!IsDisposed) { if (disposing) { Log.DebugFormat("Disposing unit of work {0}", this); DestroyAppliedEventHandler(); UnitOfWorkContext.Unbind(); } IsDisposed = true; } }
public IUnitOfWorkContext CreateUnitOfWork(Guid commandId) { if (UnitOfWorkContext.Current != null) { throw new InvalidOperationException("There is already a unit of work created for this context."); } var store = NcqrsEnvironment.Get <IEventStore>(); var bus = NcqrsEnvironment.Get <IEventBus>(); var snapshotStore = NcqrsEnvironment.Get <ISnapshotStore>(); var snapshottingPolicy = NcqrsEnvironment.Get <ISnapshottingPolicy>(); var aggregateCreationStrategy = NcqrsEnvironment.Get <IAggregateRootCreationStrategy>(); var aggregateSnappshotter = NcqrsEnvironment.Get <IAggregateSnapshotter>(); var repository = new DomainRepository(aggregateCreationStrategy, aggregateSnappshotter); var unitOfWork = new UnitOfWork(commandId, repository, store, snapshotStore, bus, snapshottingPolicy); UnitOfWorkContext.Bind(unitOfWork); return(unitOfWork); }