This repository has been archived by the owner on Dec 14, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 239
/
EventBusUserAccountRepository.cs
115 lines (96 loc) · 3.06 KB
/
EventBusUserAccountRepository.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright (c) Brock Allen. All rights reserved.
* see license.txt
*/
using System;
namespace BrockAllen.MembershipReboot
{
public class EventBusUserAccountRepository<TAccount> : IUserAccountRepository<TAccount>
where TAccount : UserAccount
{
IEventSource source;
internal IUserAccountRepository<TAccount> inner;
IEventBus validationBus;
IEventBus eventBus;
public EventBusUserAccountRepository(IEventSource source, IUserAccountRepository<TAccount> inner, IEventBus validationBus, IEventBus eventBus)
{
if (source == null) throw new ArgumentNullException("source");
if (inner == null) throw new ArgumentNullException("inner");
if (validationBus == null) throw new ArgumentNullException("validationBus");
if (eventBus == null) throw new ArgumentNullException("eventBus");
this.source = source;
this.inner = inner;
this.validationBus = validationBus;
this.eventBus = eventBus;
}
private void RaiseValidation()
{
foreach (var evt in source.GetEvents())
{
this.validationBus.RaiseEvent(evt);
}
}
private void RaiseEvents()
{
foreach (var evt in source.GetEvents())
{
this.eventBus.RaiseEvent(evt);
}
source.Clear();
}
public TAccount Create()
{
return inner.Create();
}
public void Add(TAccount item)
{
RaiseValidation();
inner.Add(item);
RaiseEvents();
}
public void Remove(TAccount item)
{
RaiseValidation();
inner.Remove(item);
RaiseEvents();
}
public void Update(TAccount item)
{
RaiseValidation();
inner.Update(item);
RaiseEvents();
}
public TAccount GetByID(Guid id)
{
return inner.GetByID(id);
}
public TAccount GetByUsername(string username)
{
return inner.GetByUsername(username);
}
public TAccount GetByUsername(string tenant, string username)
{
return inner.GetByUsername(tenant, username);
}
public TAccount GetByEmail(string tenant, string email)
{
return inner.GetByEmail(tenant, email);
}
public TAccount GetByMobilePhone(string tenant, string phone)
{
return inner.GetByMobilePhone(tenant, phone);
}
public TAccount GetByVerificationKey(string key)
{
return inner.GetByVerificationKey(key);
}
public TAccount GetByLinkedAccount(string tenant, string provider, string id)
{
return inner.GetByLinkedAccount(tenant, provider, id);
}
public TAccount GetByCertificate(string tenant, string thumbprint)
{
return inner.GetByCertificate(tenant, thumbprint);
}
}
}