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 cdmdotnet.Logging;
11 : using Cqrs.Configuration;
12 : using Cqrs.Events;
13 :
14 : namespace Cqrs.Domain
15 : {
16 : /// <summary>
17 : /// A process manager that you can implement <see cref="IEventHandler"/> instances on top of.
18 : /// </summary>
19 : /// <typeparam name="TAuthenticationToken">The <see cref="Type"/> of authentication token.</typeparam>
20 : /// <typeparam name="TSaga">The <see cref="Type"/> of <see cref="ISaga{TAuthenticationToken}"/>.</typeparam>
21 : public abstract class SagaEventHandler<TAuthenticationToken, TSaga>
22 : where TSaga : ISaga<TAuthenticationToken>
23 1 : {
24 : /// <summary>
25 : /// Gets or set the <see cref="ISagaUnitOfWork{TAuthenticationToken}"/>.
26 : /// </summary>
27 : protected ISagaUnitOfWork<TAuthenticationToken> SagaUnitOfWork { get; private set; }
28 :
29 : /// <summary>
30 : /// Gets or set the <see cref="IDependencyResolver"/>.
31 : /// </summary>
32 : protected IDependencyResolver DependencyResolver { get; private set; }
33 :
34 : /// <summary>
35 : /// Gets or set the <see cref="ILogger"/>.
36 : /// </summary>
37 : protected ILogger Logger { get; private set; }
38 :
39 : /// <summary>
40 : /// A constructor for the <see cref="Cqrs.Domain.Factories.IAggregateFactory"/>
41 : /// </summary>
42 1 : protected SagaEventHandler(IDependencyResolver dependencyResolver, ILogger logger)
43 : : this(dependencyResolver, logger, dependencyResolver.Resolve<ISagaUnitOfWork<TAuthenticationToken>>())
44 : {
45 : }
46 :
47 : /// <summary>
48 : /// Instantiate a new instance of <see cref="SagaEventHandler{TAuthenticationToken,TSaga}"/>
49 : /// </summary>
50 1 : protected SagaEventHandler(IDependencyResolver dependencyResolver, ILogger logger, ISagaUnitOfWork<TAuthenticationToken> sagaUnitOfWork)
51 : {
52 : DependencyResolver = dependencyResolver;
53 : Logger = logger;
54 : SagaUnitOfWork = sagaUnitOfWork;
55 : }
56 :
57 : /// <summary>
58 : /// Gets the <typeparamref name="TSaga"/> from the <see cref="SagaUnitOfWork"/>.
59 : /// </summary>
60 : /// <param name="id">The identifier of the <typeparamref name="TSaga"/> to get.</param>
61 1 : protected virtual TSaga GetSaga(Guid id)
62 : {
63 : return SagaUnitOfWork.Get<TSaga>(id);
64 : }
65 : }
66 : }
|