Skip to content

Commit b10a0c4

Browse files
committed
Removed the ConfigurationStore singleton
1 parent dcd4099 commit b10a0c4

File tree

27 files changed

+158
-79
lines changed

27 files changed

+158
-79
lines changed

src/Server/Coderr.Server.App.Tests/Core/Accounts/CommandHandlers/RegisterAccountHandlerTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ public class RegisterAccountHandlerTests
1717
[Fact]
1818
public async Task Should_create_a_new_account()
1919
{
20-
ConfigurationStore.Instance = new TestStore();
20+
var configStore = new TestStore();
2121
var repos = Substitute.For<IAccountRepository>();
2222
var cmd = new RegisterAccount("rne", "yo", "[email protected]");
2323
var context = Substitute.For<IMessageContext>();
2424
repos.When(x => x.CreateAsync(Arg.Any<Account>()))
2525
.Do(x => x.Arg<Account>().SetId(3));
2626

2727

28-
var sut = new RegisterAccountHandler(repos);
28+
var sut = new RegisterAccountHandler(repos, configStore);
2929
await sut.HandleAsync(context, cmd);
3030
await repos.Received().CreateAsync(Arg.Any<Account>());
3131
}
3232

3333
[Fact]
3434
public async Task Should_inform_the_rest_of_the_system_about_the_new_account()
3535
{
36-
ConfigurationStore.Instance = new TestStore();
36+
var configStore = new TestStore();
3737
var repos = Substitute.For<IAccountRepository>();
3838
var context = Substitute.For<IMessageContext>();
3939
var cmd = new RegisterAccount("rne", "yo", "[email protected]");
4040
repos.When(x => x.CreateAsync(Arg.Any<Account>()))
4141
.Do(x => x.Arg<Account>().SetId(3));
4242

4343

44-
var sut = new RegisterAccountHandler(repos);
44+
var sut = new RegisterAccountHandler(repos, configStore);
4545
await sut.HandleAsync(context, cmd);
4646

4747
await context.Received().SendAsync(Arg.Any<AccountRegistered>());
@@ -51,15 +51,15 @@ public async Task Should_inform_the_rest_of_the_system_about_the_new_account()
5151
[Fact]
5252
public async Task Should_send_activation_email()
5353
{
54-
ConfigurationStore.Instance = new TestStore();
54+
var configStore = new TestStore();
5555
var repos = Substitute.For<IAccountRepository>();
5656
var context = Substitute.For<IMessageContext>();
5757
var cmd = new RegisterAccount("rne", "yo", "[email protected]");
5858
repos.When(x => x.CreateAsync(Arg.Any<Account>()))
5959
.Do(x => x.Arg<Account>().SetId(3));
6060

6161

62-
var sut = new RegisterAccountHandler(repos);
62+
var sut = new RegisterAccountHandler(repos, configStore);
6363
await sut.HandleAsync(context, cmd);
6464

6565
await context.Received().SendAsync(Arg.Any<SendEmail>());

src/Server/Coderr.Server.App.Tests/Core/Applications/Commands/InviteUserHandlerTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class InviteUserHandlerTests
2626
private readonly InviteUserHandler _sut;
2727
private readonly IUserRepository _userRepository;
2828
private IMessageContext _context;
29+
private TestStore _configStore;
2930

3031
public InviteUserHandlerTests()
3132
{
@@ -35,8 +36,8 @@ public InviteUserHandlerTests()
3536
_userRepository.GetUserAsync(1).Returns(new User(1, "First"));
3637
_applicationRepository.GetByIdAsync(1).Returns(new Application(1, "MyApp"));
3738
_context = Substitute.For<IMessageContext>();
38-
ConfigurationStore.Instance = new TestStore();
39-
_sut = new InviteUserHandler(_invitationRepository, _userRepository, _applicationRepository);
39+
_configStore = new TestStore();
40+
_sut = new InviteUserHandler(_invitationRepository, _userRepository, _applicationRepository, _configStore);
4041
}
4142

4243
[Fact]

src/Server/Coderr.Server.App/Core/Accounts/CommandHandlers/RegisterAccountHandler.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ public class RegisterAccountHandler : IMessageHandler<RegisterAccount>
2525
{
2626
private readonly IAccountRepository _repository;
2727
private ILog _logger = LogManager.GetLogger(typeof(RegisterAccountHandler));
28+
private ConfigurationStore _configStore;
2829

2930
/// <summary>
3031
/// Creates a new instance of <see cref="RegisterAccountHandler" />.
3132
/// </summary>
3233
/// <param name="repository">repos</param>
33-
public RegisterAccountHandler(IAccountRepository repository)
34+
public RegisterAccountHandler(IAccountRepository repository, ConfigurationStore configStore)
3435
{
3536
_repository = repository;
37+
_configStore = configStore;
3638
}
3739

3840
/// <summary>
@@ -86,7 +88,7 @@ private async Task SendAccountInfo(IMessageContext context, string userName)
8688
{
8789
var account = await _repository.GetByUserNameAsync(userName);
8890

89-
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
91+
var config = _configStore.Load<BaseConfiguration>();
9092
//TODO: HTML email
9193
var msg = new EmailMessage
9294
{
@@ -108,7 +110,7 @@ private async Task SendAccountInfo(IMessageContext context, string userName)
108110

109111
private Task SendVerificationEmail(IMessageContext context, Account account)
110112
{
111-
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
113+
var config = _configStore.Load<BaseConfiguration>();
112114
//TODO: HTML email
113115
var msg = new EmailMessage
114116
{

src/Server/Coderr.Server.App/Core/Accounts/CommandHandlers/RegisterSimpleHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ internal class RegisterSimpleHandler : IMessageHandler<RegisterSimple>
2121
{
2222
private readonly ILog _logger = LogManager.GetLogger(typeof(RegisterSimpleHandler));
2323
private readonly IAccountRepository _repository;
24+
private ConfigurationStore _configStore;
2425

25-
public RegisterSimpleHandler(IAccountRepository repository)
26+
public RegisterSimpleHandler(IAccountRepository repository, ConfigurationStore configStore)
2627
{
2728
_repository = repository;
29+
_configStore = configStore;
2830
}
2931

3032
public async Task HandleAsync(IMessageContext context, RegisterSimple command)
@@ -65,7 +67,7 @@ public async Task HandleAsync(IMessageContext context, RegisterSimple command)
6567

6668
private Task SendAccountEmail(IMessageContext context, Account account, string password)
6769
{
68-
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
70+
var config = _configStore.Load<BaseConfiguration>();
6971
//TODO: HTML email
7072
var msg = new EmailMessage
7173
{

src/Server/Coderr.Server.App/Core/Accounts/CommandHandlers/RequestPasswordResetHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ internal class RequestPasswordResetHandler : IMessageHandler<RequestPasswordRese
1717
{
1818
private readonly IAccountRepository _accountRepository;
1919
private readonly ILog _logger = LogManager.GetLogger(typeof(RequestPasswordResetHandler));
20+
private ConfigurationStore _configStore;
2021

21-
public RequestPasswordResetHandler(IAccountRepository accountRepository)
22+
public RequestPasswordResetHandler(IAccountRepository accountRepository, ConfigurationStore configStore)
2223
{
2324
_accountRepository = accountRepository;
25+
_configStore = configStore;
2426
}
2527

2628
public async Task HandleAsync(IMessageContext context, RequestPasswordReset command)
@@ -35,7 +37,7 @@ public async Task HandleAsync(IMessageContext context, RequestPasswordReset comm
3537
account.RequestPasswordReset();
3638
await _accountRepository.UpdateAsync(account);
3739

38-
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
40+
var config = _configStore.Load<BaseConfiguration>();
3941
var cmd = new SendTemplateEmail("Password reset", "ResetPassword")
4042
{
4143
To = account.Email,

src/Server/Coderr.Server.App/Core/Invitations/CommandHandlers/InviteUserHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Configuration;
23
using System.Linq;
34
using System.Security;
45
using System.Security.Claims;
@@ -34,6 +35,7 @@ public class InviteUserHandler : IMessageHandler<InviteUser>
3435
private readonly IInvitationRepository _invitationRepository;
3536
private readonly IUserRepository _userRepository;
3637
private readonly ILog _logger = LogManager.GetLogger(typeof(InviteUserHandler));
38+
private ConfigurationStore _configStore;
3739

3840
/// <summary>
3941
/// Creates a new instance of <see cref="InviteUserHandler" />.
@@ -42,11 +44,12 @@ public class InviteUserHandler : IMessageHandler<InviteUser>
4244
/// <param name="userRepository">To load inviter and invitee</param>
4345
/// <param name="applicationRepository">Add pending member</param>
4446
public InviteUserHandler(IInvitationRepository invitationRepository,
45-
IUserRepository userRepository, IApplicationRepository applicationRepository)
47+
IUserRepository userRepository, IApplicationRepository applicationRepository, ConfigurationStore configStore)
4648
{
4749
_invitationRepository = invitationRepository;
4850
_userRepository = userRepository;
4951
_applicationRepository = applicationRepository;
52+
_configStore = configStore;
5053
}
5154

5255
/// <inheritdoc />
@@ -127,7 +130,7 @@ public async Task HandleAsync(IMessageContext context, InviteUser command)
127130
/// <returns>task</returns>
128131
protected virtual async Task SendInvitationEmailAsync(IMessageContext context, Invitation invitation, string reason)
129132
{
130-
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
133+
var config = _configStore.Load<BaseConfiguration>();
131134
var url = config.BaseUrl.ToString().TrimEnd('/');
132135
if (string.IsNullOrEmpty(reason))
133136
reason = "";

src/Server/Coderr.Server.App/Core/Notifications/EventHandlers/CheckForFeedbackNotificationsToSend.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ public class CheckForFeedbackNotificationsToSend :
1919
IMessageHandler<FeedbackAttachedToIncident>
2020
{
2121
private readonly INotificationsRepository _notificationsRepository;
22+
private ConfigurationStore _configStore;
2223

2324
/// <summary>
2425
/// Creates a new instance of <see cref="CheckForNotificationsToSend" />.
2526
/// </summary>
2627
/// <param name="notificationsRepository">To load notification configuration</param>
27-
public CheckForFeedbackNotificationsToSend(INotificationsRepository notificationsRepository)
28+
public CheckForFeedbackNotificationsToSend(INotificationsRepository notificationsRepository, ConfigurationStore configStore)
2829
{
2930
_notificationsRepository = notificationsRepository;
31+
_configStore = configStore;
3032
}
3133

3234
/// <inheritdoc/>
@@ -40,7 +42,7 @@ public async Task HandleAsync(IMessageContext context, FeedbackAttachedToInciden
4042
continue;
4143

4244
var notificationEmail = await context.QueryAsync(new GetAccountEmailById(setting.AccountId));
43-
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
45+
var config = _configStore.Load<BaseConfiguration>();
4446

4547
var shortName = incident.Description.Length > 40
4648
? incident.Description.Substring(0, 40) + "..."

src/Server/Coderr.Server.App/Core/Notifications/EventHandlers/CheckForNotificationsToSend.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using codeRR.Server.Api.Core.Incidents.Events;
44
using codeRR.Server.App.Core.Notifications.Tasks;
55
using codeRR.Server.App.Core.Users;
6+
using codeRR.Server.Infrastructure.Configuration;
67
using DotNetCqs;
78
using Griffin.Container;
89

@@ -17,17 +18,19 @@ public class CheckForNotificationsToSend :
1718
{
1819
private readonly INotificationsRepository _notificationsRepository;
1920
private readonly IUserRepository _userRepository;
21+
private ConfigurationStore _configStore;
2022

2123
/// <summary>
2224
/// Creates a new instance of <see cref="CheckForNotificationsToSend" />.
2325
/// </summary>
2426
/// <param name="notificationsRepository">To load notification configuration</param>
2527
/// <param name="userRepository">To load user info</param>
2628
public CheckForNotificationsToSend(INotificationsRepository notificationsRepository,
27-
IUserRepository userRepository)
29+
IUserRepository userRepository, ConfigurationStore configStore)
2830
{
2931
_notificationsRepository = notificationsRepository;
3032
_userRepository = userRepository;
33+
_configStore = configStore;
3134
}
3235

3336
/// <summary>
@@ -64,12 +67,12 @@ private async Task CreateNotification(IMessageContext context, ReportAddedToInci
6467
{
6568
if (state == NotificationState.Email)
6669
{
67-
var email = new SendIncidentEmail();
70+
var email = new SendIncidentEmail(_configStore);
6871
await email.SendAsync(context, accountId.ToString(), e.Incident, e.Report);
6972
}
7073
else
7174
{
72-
var handler = new SendIncidentSms(_userRepository);
75+
var handler = new SendIncidentSms(_userRepository, _configStore);
7376
await handler.SendAsync(accountId, e.Incident, e.Report);
7477
}
7578
}

src/Server/Coderr.Server.App/Core/Notifications/Tasks/SendIncidentEmail.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ namespace codeRR.Server.App.Core.Notifications.Tasks
1515
/// </summary>
1616
public class SendIncidentEmail
1717
{
18+
private ConfigurationStore _configStore;
19+
20+
public SendIncidentEmail(ConfigurationStore configStore)
21+
{
22+
_configStore = configStore;
23+
}
24+
1825
/// <summary>
1926
/// Send
2027
/// </summary>
@@ -29,7 +36,7 @@ public async Task SendAsync(IMessageContext context, string idOrEmailAddress, In
2936
if (incident == null) throw new ArgumentNullException("incident");
3037
if (report == null) throw new ArgumentNullException("report");
3138

32-
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
39+
var config = _configStore.Load<BaseConfiguration>();
3340

3441
var shortName = incident.Name.Length > 40
3542
? incident.Name.Substring(0, 40) + "..."

src/Server/Coderr.Server.App/Core/Notifications/Tasks/SendIncidentSms.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ namespace codeRR.Server.App.Core.Notifications.Tasks
1616
public class SendIncidentSms
1717
{
1818
private readonly IUserRepository _userRepository;
19+
private ConfigurationStore _configStore;
1920

2021
/// <summary>
2122
/// Creates a new instance of <see cref="SendIncidentSms" />.
2223
/// </summary>
2324
/// <param name="userRepository">to fetch phone number</param>
2425
/// <exception cref="ArgumentNullException">userRepository</exception>
25-
public SendIncidentSms(IUserRepository userRepository)
26+
public SendIncidentSms(IUserRepository userRepository, ConfigurationStore configStore)
2627
{
2728
if (userRepository == null) throw new ArgumentNullException("userRepository");
2829
_userRepository = userRepository;
30+
_configStore = configStore;
2931
}
3032

3133
/// <summary>
@@ -47,7 +49,7 @@ public async Task SendAsync(int accountId, IncidentSummaryDTO incident, ReportDT
4749
if (string.IsNullOrEmpty(settings.MobileNumber))
4850
return; //TODO: LOG
4951

50-
var config = ConfigurationStore.Instance.Load<BaseConfiguration>();
52+
var config = _configStore.Load<BaseConfiguration>();
5153
var url = config.BaseUrl;
5254
var shortName = incident.Name.Length > 20
5355
? incident.Name.Substring(0, 20) + "..."

0 commit comments

Comments
 (0)