-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
76 lines (61 loc) · 2.99 KB
/
Program.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
68
69
70
71
72
73
74
75
76
using BinaryDad.AggregateDal.Models;
using StructureMap;
using System;
namespace BinaryDad.AggregateDal
{
internal class Program
{
private static void Main(string[] args)
{
// build container
var container = CreateContainer();
// get instance via structuremap, as is typical
var settlementAttemptDataAccess = container.GetInstance<ISettlementAttemptDataAccess>();
#region Add attempt
var newAttempt = new SettlementAttempt
{
ClientFirstName = "Ryan",
ClientLastName = "Peters",
CreatedBy = "rpeters"
};
settlementAttemptDataAccess.AddAttempt(newAttempt);
// in most cases, the QuickBase DAL will update "RecordId" and
// the EF DAL will update "Id"
Console.WriteLine($"Attempt ID (SQL) => {newAttempt.Id}");
Console.WriteLine($"Attempt ID (QuickBase) => {newAttempt.RecordId}");
#endregion
#region Get attempt
var attempt = settlementAttemptDataAccess.GetAttempt(1234);
// dump the attempt
Console.WriteLine($"{nameof(attempt.Id)} => {attempt.Id}");
Console.WriteLine($"{nameof(attempt.RecordId)} => {attempt.RecordId}");
Console.WriteLine($"{nameof(attempt.ClientFirstName)} => {attempt.ClientFirstName}");
Console.WriteLine($"{nameof(attempt.ClientLastName)} => {attempt.ClientLastName}");
Console.WriteLine($"{nameof(attempt.Created)} => {attempt.Created}");
Console.WriteLine($"{nameof(attempt.CreatedBy)} => {attempt.CreatedBy}");
#endregion
// pause
Console.ReadLine();
}
private static IContainer CreateContainer()
{
/* NOTES:
* The StructureMap container will drive the instances of the DALs that will be invoked.
* DALs that inherit from AggregateDataAccess<T> will automatically aggregate types implementing T
* and will invoke them. This means we can have implementations of QuickBaseXxxDataAccess and
* EfXxxDataAccess that focus solely on their own operations. Once we decide to turn off a feature
* (i.e., we no longer need to save to QB for a particular DAL), we can change the .Use<T>()
* to use a regular EfXxxDataAccess instance.
*
* NO OTHER PARTS OF THE CODEBASE WOULD NEED TO BE TOUCHED, as we're only changing the instance
* of a DAL from an aggregate to a singular instance */
return new Container(c =>
{
// when both DALs are needed (SQL and QuickBase)
c.For<ISettlementAttemptDataAccess>().Singleton().Use<SettlementAttemptDataAccess>();
// when only SQL is needed
//c.For<ISettlementAttemptDataAccess>().Singleton().Use<EfSettlementAttemptDataAccess>();
});
}
}
}