Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using Cqrs.Events;
11 :
12 : namespace Cqrs.Domain
13 : {
14 : /// <summary>
15 : /// Provides a basic container to control when <see cref="IEvent{TAuthenticationToken}">events</see> are store in an <see cref="IEventStore{TAuthenticationToken}"/> and then published on an <see cref="IEventPublisher{TAuthenticationToken}"/>.
16 : /// </summary>
17 : public interface IUnitOfWork<TAuthenticationToken>
18 : {
19 : /// <summary>
20 : /// Add an item into the <see cref="IUnitOfWork{TAuthenticationToken}"/> ready to be committed.
21 : /// </summary>
22 : /// <typeparam name="TAggregateRoot">The <see cref="Type"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/> the <see cref="IEvent{TAuthenticationToken}"/> was raised in.</typeparam>
23 1 : void Add<TAggregateRoot>(TAggregateRoot aggregate, bool useSnapshots = false)
24 : where TAggregateRoot : IAggregateRoot<TAuthenticationToken>;
25 :
26 : /// <summary>
27 : /// Get an item from the <see cref="IUnitOfWork{TAuthenticationToken}"/> if it has already been loaded.
28 : /// </summary>
29 : /// <typeparam name="TAggregateRoot">The <see cref="Type"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/> the <see cref="IEvent{TAuthenticationToken}"/> was raised in.</typeparam>
30 1 : TAggregateRoot Get<TAggregateRoot>(Guid id, int? expectedVersion = null, bool useSnapshots = false)
31 : where TAggregateRoot : IAggregateRoot<TAuthenticationToken>;
32 :
33 : /// <summary>
34 : /// Get an item from the <see cref="IUnitOfWork{TAuthenticationToken}"/> up to and including the provided <paramref name="version"/>.
35 : /// </summary>
36 : /// <typeparam name="TAggregateRoot">The <see cref="Type"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/> the <see cref="IEvent{TAuthenticationToken}"/> was raised in.</typeparam>
37 : /// <param name="id">The <see cref="IAggregateRoot{TAuthenticationToken}.Id"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/>.</param>
38 : /// <param name="version">Load events up-to and including from this version</param>
39 1 : TAggregateRoot GetToVersion<TAggregateRoot>(Guid id, int version)
40 : where TAggregateRoot : IAggregateRoot<TAuthenticationToken>;
41 :
42 : /// <summary>
43 : /// Get an item from the <see cref="IUnitOfWork{TAuthenticationToken}"/> up to and including the provided <paramref name="versionedDate"/>.
44 : /// </summary>
45 : /// <typeparam name="TAggregateRoot">The <see cref="Type"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/> the <see cref="IEvent{TAuthenticationToken}"/> was raised in.</typeparam>
46 : /// <param name="id">The <see cref="IAggregateRoot{TAuthenticationToken}.Id"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/>.</param>
47 : /// <param name="versionedDate">Load events up-to and including from this <see cref="DateTime"/></param>
48 1 : TAggregateRoot GetToDate<TAggregateRoot>(Guid id, DateTime versionedDate)
49 : where TAggregateRoot : IAggregateRoot<TAuthenticationToken>;
50 :
51 : /// <summary>
52 : /// Commit any changed <see cref="AggregateRoot{TAuthenticationToken}"/> added to this <see cref="IUnitOfWork{TAuthenticationToken}"/> via <see cref="Add{T}"/>
53 : /// </summary>
54 1 : void Commit();
55 : }
56 : }
|