-
Notifications
You must be signed in to change notification settings - Fork 2
/
Projector.cs
67 lines (55 loc) · 2.79 KB
/
Projector.cs
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
#region Usings
using Microsoft.Extensions.Configuration;
using Records.Shared.Configuration;
using Records.Shared.Projection.Abstractions;
////using Records.Shared.Infra.Persistence.Abstractions; // IMPORTANT: Do not reference this.
#endregion
namespace Records.Shared.Infra.Projection;
/// <summary>
/// Represents a base class for Projectors.
/// </summary>
public abstract class Projector
{
#region Contructor
/// <inheritdoc cref="IDbSession"/>
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"StyleCop.CSharp.MaintainabilityRules",
"SA1401:Fields should be private",
Justification = "I prefer to use it as field just in protected fields in base classes like Repository base class.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Design",
"CA1051:Do not declare visible instance fields",
Justification = "I prefer to use it as field just in protected fields in base classes like Repository base class.")]
//// ReSharper disable once InconsistentNaming
protected readonly IDbSession _dbSession;
////public IDbSession DbSession { get; init; }
/// <summary>Used to read from the main database.</summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"StyleCop.CSharp.MaintainabilityRules",
"SA1401:Fields should be private",
Justification = "I prefer to use it as field just in protected fields in base classes like Repository base class.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Design",
"CA1051:Do not declare visible instance fields",
Justification = "I prefer to use it as field just in protected fields in base classes like Repository base class.")]
//// ReSharper disable once InconsistentNaming
protected readonly string? _sourceConnectionString;
#endregion
#region Contructor
/// <summary>
/// Initializes a new instance of the <see cref="Projector"/> class.
/// </summary>
/// <param name="configuration">Represents a set of key/value application configuration properties.</param>
/// <param name="dbSession">Represents a session in the database/UOW that contains a connection and a transaction.</param>
/// <exception cref="ArgumentNullException">When some argument for the constructor parameters is null.</exception>
protected Projector(
IConfiguration configuration,
IDbSession dbSession)
{
_dbSession = dbSession ?? throw new ArgumentNullException(nameof(dbSession));
SqlServerSettings databaseSettings = configuration.GetSectionOrThrow<SqlServerSettings>(SqlServerSettings.SettingsKey);
// Source database used to read from the "Source" and then project to the "Projection" database.
_sourceConnectionString = databaseSettings.SourceConnectionString;
}
#endregion
}