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.Domain;
11 :
12 : namespace Cqrs.Commands
13 : {
14 : /// <summary>
15 : /// A <see cref="ICommandHandle"/> for working with <see cref="DtoCommand{TAuthenticationToken,TDto}"/>.
16 : /// </summary>
17 : /// <typeparam name="TAuthenticationToken">The <see cref="Type"/> of authentication token.</typeparam>
18 : /// <typeparam name="TDto">The <see cref="Type"/> of <see cref="IDto"/> this command targets.</typeparam>
19 : public class DtoCommandHandler<TAuthenticationToken, TDto> : ICommandHandler<TAuthenticationToken, DtoCommand<TAuthenticationToken, TDto>>
20 : where TDto : IDto
21 1 : {
22 : private IUnitOfWork<TAuthenticationToken> UnitOfWork { get; set; }
23 :
24 : /// <summary>
25 : /// Instantiates a new instance of <see cref="DtoCommandHandler{TAuthenticationToken,TDto}"/>
26 : /// </summary>
27 1 : public DtoCommandHandler(IUnitOfWork<TAuthenticationToken> unitOfWork)
28 : {
29 : UnitOfWork = unitOfWork;
30 : }
31 :
32 : #region Implementation of IMessageHandler<in DtoCommand<UserDto>>
33 :
34 : /// <summary>
35 : /// Responds to the provided <paramref name="message"/>.
36 : /// </summary>
37 : /// <param name="message">The <see cref="DtoCommand{TAuthenticationToken,TDto}"/> to respond to or "handle"</param>
38 1 : public void Handle(DtoCommand<TAuthenticationToken, TDto> message)
39 : {
40 : var item = new DtoAggregateRoot<TAuthenticationToken, TDto>(message.Id, message.Original, message.New);
41 : UnitOfWork.Add(item);
42 : UnitOfWork.Commit();
43 : }
44 :
45 : #endregion
46 : }
47 : }
|