/// <summary> /// Sets the unit of work for type <typeparamref name="T" /> to its default behavior. /// </summary> public static void ConfigureDefault() { Create = delegate { }; Action <UnitOfWork <T> > dispose = work => work.disposables.Dispose(); Commit = work => dispose(work); Reject = work => dispose(work); }
/// <summary> /// Initializes a new instance of the <see cref="UnitOfWork{T}"/> class. /// </summary> /// <param name="create">A delegate that is called when the unit of work is created.</param> /// <param name="reject">A delegate that is called when the unit of work is rejected.</param> /// <param name="commit">A delegate that is called when the unit of work is commited.</param> public UnitOfWork(Func <T> create, Action <T> reject = null, Action <T> commit = null) : this() { if (isOutermost) { AddResource(create()); if (commit != null) { this.commit = work => commit(work.Resource <T>()); } if (reject != null) { this.reject = work => reject(work.Resource <T>()); } } }