-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdateDomainModelCommandHandler.cs
More file actions
85 lines (81 loc) · 3.99 KB
/
UpdateDomainModelCommandHandler.cs
File metadata and controls
85 lines (81 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// =================================================================================================================================
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================
using RapidField.SolidInstruments.Command;
using RapidField.SolidInstruments.Core.Concurrency;
using RapidField.SolidInstruments.Core.Domain;
using System;
using System.Collections.Generic;
namespace RapidField.SolidInstruments.DataAccess
{
/// <summary>
/// Processes a single <see cref="IUpdateDomainModelCommand{TModel}" />.
/// </summary>
/// <typeparam name="TIdentifier">
/// The type of the unique primary identifier for the model.
/// </typeparam>
/// <typeparam name="TDomainModel">
/// The type of the domain model to which the data access model is mapped.
/// </typeparam>
/// <typeparam name="TDataAccessModel">
/// The type of the data access model.
/// </typeparam>
/// <typeparam name="TCommand">
/// The type of the command that is processed by the handler.
/// </typeparam>
public class UpdateDomainModelCommandHandler<TIdentifier, TDomainModel, TDataAccessModel, TCommand> : UpdateDomainModelCommandHandler<TDomainModel, TCommand>
where TIdentifier : IComparable, IComparable<TIdentifier>, IEquatable<TIdentifier>
where TDomainModel : class, IDomainModel<TIdentifier>
where TDataAccessModel : class, IDataAccessModel<TIdentifier, TDomainModel>, new()
where TCommand : class, IUpdateDomainModelCommand<TDomainModel>
{
/// <summary>
/// Initializes a new instance of the
/// <see cref="UpdateDomainModelCommandHandler{TIdentifier, TDomainModel, TDataAccessModel, TCommand}" /> class.
/// </summary>
/// <param name="mediator">
/// A processing intermediary that is used to process sub-commands.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="mediator" /> is <see langword="null" />.
/// </exception>
public UpdateDomainModelCommandHandler(ICommandMediator mediator)
: base(mediator)
{
return;
}
/// <summary>
/// Releases all resources consumed by the current
/// <see cref="UpdateDomainModelCommandHandler{TIdentifier, TDomainModel, TDataAccessModel, TCommand}" />.
/// </summary>
/// <param name="disposing">
/// A value indicating whether or not managed resources should be released.
/// </param>
protected override void Dispose(Boolean disposing) => base.Dispose(disposing);
/// <summary>
/// Updates the specified domain model.
/// </summary>
/// <param name="model">
/// The model to update.
/// </param>
/// <param name="labels">
/// A collection of textual labels that provide categorical and/or contextual information about the command.
/// </param>
/// <param name="correlationIdentifier">
/// A unique identifier to assign to sub-commands.
/// </param>
/// <param name="mediator">
/// A processing intermediary that is used to process sub-commands.
/// </param>
/// <param name="controlToken">
/// A token that represents and manages contextual thread safety.
/// </param>
protected override void UpdateDomainModel(TDomainModel model, IEnumerable<String> labels, Guid correlationIdentifier, ICommandMediator mediator, IConcurrencyControlToken controlToken)
{
var dataAccessModel = new TDataAccessModel();
dataAccessModel.HydrateFromDomainModel(model);
var dataAccessModelCommand = new CreateOrUpdateDataAccessModelCommand<TIdentifier, TDataAccessModel>(dataAccessModel);
mediator.Process(dataAccessModelCommand);
}
}
}