Skip to content

Commit 95480d4

Browse files
Fix IOptionMonitor pattern (#112)
1 parent 3921920 commit 95480d4

File tree

12 files changed

+52
-52
lines changed

12 files changed

+52
-52
lines changed

src/FrontEnds/WebMvc/Controllers/ConsultationController.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ namespace MedicalSystem.FrontEnds.WebMvc.Controllers
1717
public class ConsultationController : Controller
1818
{
1919
private readonly IHttpClientFactory _httpClientFactory;
20-
private readonly ConsultationOptions _consultationOptions;
20+
private readonly IOptionsMonitor<ConsultationOptions> _consultationOptionsAccessor;
2121

2222
public ConsultationController(IHttpClientFactory httpClientFactory,
2323
IOptionsMonitor<ConsultationOptions> consultationOptionsAccessor)
2424
{
2525
_httpClientFactory = httpClientFactory;
26-
_consultationOptions = consultationOptionsAccessor.CurrentValue;
26+
_consultationOptionsAccessor = consultationOptionsAccessor;
2727
}
2828

2929
public async Task<IActionResult> Index()
3030
{
3131
HttpClient httpClient = _httpClientFactory.CreateClient();
32-
HttpResponseMessage consultationApiResponseMessage = await httpClient.GetAsync(_consultationOptions.ConsultationGatewayUrl);
32+
HttpResponseMessage consultationApiResponseMessage = await httpClient.GetAsync(_consultationOptionsAccessor.CurrentValue.ConsultationGatewayUrl);
3333
if (consultationApiResponseMessage.IsSuccessStatusCode)
3434
{
3535
using Stream consultationApiResponseStream = await consultationApiResponseMessage.Content.ReadAsStreamAsync();
@@ -53,7 +53,7 @@ public async Task<IActionResult> Details(int? id)
5353
return RedirectToAction(nameof(Index));
5454
}
5555
HttpClient httpClient = _httpClientFactory.CreateClient();
56-
var consultationGetByIdGatewayUrl = $"{_consultationOptions.ConsultationGatewayUrl}/{id}";
56+
var consultationGetByIdGatewayUrl = $"{_consultationOptionsAccessor.CurrentValue.ConsultationGatewayUrl}/{id}";
5757
HttpResponseMessage consultationApiResponseMessage = await httpClient.GetAsync(consultationGetByIdGatewayUrl);
5858
if (consultationApiResponseMessage.StatusCode == HttpStatusCode.OK)
5959
{
@@ -69,7 +69,7 @@ public async Task<IActionResult> Create()
6969
HttpClient httpClient = _httpClientFactory.CreateClient();
7070

7171
HttpResponseMessage consultationAddEditInitResponseMessage =
72-
await httpClient.GetAsync(_consultationOptions.ConsultationGatewayAddEditInitDataUrl);
72+
await httpClient.GetAsync(_consultationOptionsAccessor.CurrentValue.ConsultationGatewayAddEditInitDataUrl);
7373
if (consultationAddEditInitResponseMessage.StatusCode != HttpStatusCode.OK)
7474
{
7575
return StatusCode((int)consultationAddEditInitResponseMessage.StatusCode);
@@ -120,7 +120,7 @@ public async Task<IActionResult> Create(ConsultationModel consultation)
120120
{
121121
HttpClient httpClient = _httpClientFactory.CreateClient();
122122
var consultationContent = new StringContent(JsonSerializer.Serialize(consultation), Encoding.UTF8, "application/json");
123-
HttpResponseMessage consultationApiResponseMessage = await httpClient.PostAsync(_consultationOptions.ConsultationGatewayUrl, consultationContent);
123+
HttpResponseMessage consultationApiResponseMessage = await httpClient.PostAsync(_consultationOptionsAccessor.CurrentValue.ConsultationGatewayUrl, consultationContent);
124124
if (consultationApiResponseMessage.IsSuccessStatusCode)
125125
{
126126
return RedirectToAction(nameof(Index));
@@ -135,15 +135,15 @@ public async Task<IActionResult> Edit(int? id)
135135
return RedirectToAction(nameof(Index));
136136
}
137137
HttpClient httpClient = _httpClientFactory.CreateClient();
138-
var consultationGetByIdGatewayUrl = $"{_consultationOptions.ConsultationGatewayUrl}/{id}";
138+
var consultationGetByIdGatewayUrl = $"{_consultationOptionsAccessor.CurrentValue.ConsultationGatewayUrl}/{id}";
139139
HttpResponseMessage consultationApiResponseMessage = await httpClient.GetAsync(consultationGetByIdGatewayUrl);
140140
if (consultationApiResponseMessage.StatusCode == HttpStatusCode.OK)
141141
{
142142
using Stream consultationApiResponseStream = await consultationApiResponseMessage.Content.ReadAsStreamAsync();
143143
ConsultationModel? consultationModel = await JsonSerializer.DeserializeAsync<ConsultationModel>(consultationApiResponseStream);
144144

145145
HttpResponseMessage consultationAddEditInitResponseMessage =
146-
await httpClient.GetAsync(_consultationOptions.ConsultationGatewayAddEditInitDataUrl);
146+
await httpClient.GetAsync(_consultationOptionsAccessor.CurrentValue.ConsultationGatewayAddEditInitDataUrl);
147147
if (consultationAddEditInitResponseMessage.StatusCode != HttpStatusCode.OK)
148148
{
149149
return StatusCode((int)consultationAddEditInitResponseMessage.StatusCode);
@@ -196,7 +196,7 @@ public async Task<IActionResult> Edit(int? id)
196196
public async Task<IActionResult> Edit(int id, ConsultationModel consultation)
197197
{
198198
HttpClient httpClient = _httpClientFactory.CreateClient();
199-
var consultationUpdateGatewayUrl = $"{_consultationOptions.ConsultationGatewayUrl}/{id}";
199+
var consultationUpdateGatewayUrl = $"{_consultationOptionsAccessor.CurrentValue.ConsultationGatewayUrl}/{id}";
200200
var consultationContent = new StringContent(JsonSerializer.Serialize(consultation), Encoding.UTF8, "application/json");
201201
HttpResponseMessage consultationApiResponseMessage = await httpClient.PutAsync(consultationUpdateGatewayUrl, consultationContent);
202202
if (consultationApiResponseMessage.IsSuccessStatusCode)
@@ -209,7 +209,7 @@ public async Task<IActionResult> Edit(int id, ConsultationModel consultation)
209209
public async Task<IActionResult> Delete(int? id)
210210
{
211211
HttpClient httpClient = _httpClientFactory.CreateClient();
212-
var consultationDeleteGatewayUrl = $"{_consultationOptions.ConsultationGatewayUrl}/{id}";
212+
var consultationDeleteGatewayUrl = $"{_consultationOptionsAccessor.CurrentValue.ConsultationGatewayUrl}/{id}";
213213
HttpResponseMessage consultationApiResponseMessage = await httpClient.DeleteAsync(consultationDeleteGatewayUrl);
214214
if (consultationApiResponseMessage.IsSuccessStatusCode)
215215
{

src/FrontEnds/WebMvc/Controllers/DoctorController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ namespace MedicalSystem.FrontEnds.WebMvc.Controllers
1515
public class DoctorController : Controller
1616
{
1717
private readonly IHttpClientFactory _httpClientFactory;
18-
private readonly DoctorOptions _doctorOptions;
18+
private readonly IOptionsMonitor<DoctorOptions> _optionsAccessor;
1919

2020
public DoctorController(IHttpClientFactory httpClientFactory,
2121
IOptionsMonitor<DoctorOptions> optionsAccessor)
2222
{
2323
_httpClientFactory = httpClientFactory;
24-
_doctorOptions = optionsAccessor.CurrentValue;
24+
_optionsAccessor = optionsAccessor;
2525
}
2626

2727
public async Task<IActionResult> Index()
2828
{
2929
HttpClient httpClient = _httpClientFactory.CreateClient();
30-
HttpResponseMessage doctorApiResponseMessage = await httpClient.GetAsync(_doctorOptions.DoctorGatewayUrl);
30+
HttpResponseMessage doctorApiResponseMessage = await httpClient.GetAsync(_optionsAccessor.CurrentValue.DoctorGatewayUrl);
3131
if (doctorApiResponseMessage.IsSuccessStatusCode)
3232
{
3333
using Stream doctorApiResponseStream = await doctorApiResponseMessage.Content.ReadAsStreamAsync();
@@ -51,7 +51,7 @@ public async Task<IActionResult> Details(int? id)
5151
return RedirectToAction(nameof(Index));
5252
}
5353
HttpClient httpClient = _httpClientFactory.CreateClient();
54-
var doctorGetByIdGatewayUrl = $"{_doctorOptions.DoctorGatewayUrl}/{id}";
54+
var doctorGetByIdGatewayUrl = $"{_optionsAccessor.CurrentValue.DoctorGatewayUrl}/{id}";
5555
HttpResponseMessage doctorApiResponseMessage = await httpClient.GetAsync(doctorGetByIdGatewayUrl);
5656
if (doctorApiResponseMessage.StatusCode == HttpStatusCode.OK)
5757
{
@@ -73,7 +73,7 @@ public async Task<IActionResult> Create(DoctorModel doctor)
7373
{
7474
HttpClient httpClient = _httpClientFactory.CreateClient();
7575
var doctorContent = new StringContent(JsonSerializer.Serialize(doctor), Encoding.UTF8, "application/json");
76-
HttpResponseMessage doctorApiResponseMessage = await httpClient.PostAsync(_doctorOptions.DoctorGatewayUrl, doctorContent);
76+
HttpResponseMessage doctorApiResponseMessage = await httpClient.PostAsync(_optionsAccessor.CurrentValue.DoctorGatewayUrl, doctorContent);
7777
if (doctorApiResponseMessage.IsSuccessStatusCode)
7878
{
7979
return RedirectToAction(nameof(Index));
@@ -88,7 +88,7 @@ public async Task<IActionResult> Edit(int? id)
8888
return RedirectToAction(nameof(Index));
8989
}
9090
HttpClient httpClient = _httpClientFactory.CreateClient();
91-
var doctorGetByIdGatewayUrl = $"{_doctorOptions.DoctorGatewayUrl}/{id}";
91+
var doctorGetByIdGatewayUrl = $"{_optionsAccessor.CurrentValue.DoctorGatewayUrl}/{id}";
9292
HttpResponseMessage doctorApiResponseMessage = await httpClient.GetAsync(doctorGetByIdGatewayUrl);
9393
if (doctorApiResponseMessage.StatusCode == HttpStatusCode.OK)
9494
{
@@ -104,7 +104,7 @@ public async Task<IActionResult> Edit(int? id)
104104
public async Task<IActionResult> Edit(int id, DoctorModel doctor)
105105
{
106106
HttpClient httpClient = _httpClientFactory.CreateClient();
107-
var doctorUpdateGatewayUrl = $"{_doctorOptions.DoctorGatewayUrl}/{id}";
107+
var doctorUpdateGatewayUrl = $"{_optionsAccessor.CurrentValue.DoctorGatewayUrl}/{id}";
108108
var doctorContent = new StringContent(JsonSerializer.Serialize(doctor), Encoding.UTF8, "application/json");
109109
HttpResponseMessage doctorApiResponseMessage = await httpClient.PutAsync(doctorUpdateGatewayUrl, doctorContent);
110110
if (doctorApiResponseMessage.IsSuccessStatusCode)
@@ -117,7 +117,7 @@ public async Task<IActionResult> Edit(int id, DoctorModel doctor)
117117
public async Task<IActionResult> Delete(int? id)
118118
{
119119
HttpClient httpClient = _httpClientFactory.CreateClient();
120-
var doctorDeleteGatewayUrl = $"{_doctorOptions.DoctorGatewayUrl}/{id}";
120+
var doctorDeleteGatewayUrl = $"{_optionsAccessor.CurrentValue.DoctorGatewayUrl}/{id}";
121121
HttpResponseMessage doctorApiResponseMessage = await httpClient.DeleteAsync(doctorDeleteGatewayUrl);
122122
if (doctorApiResponseMessage.IsSuccessStatusCode)
123123
{

src/FrontEnds/WebMvc/Controllers/PatientController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ namespace MedicalSystem.FrontEnds.WebMvc.Controllers
1515
public class PatientController : Controller
1616
{
1717
private readonly IHttpClientFactory _httpClientFactory;
18-
private readonly PatientOptions _patientOptions;
18+
private readonly IOptionsMonitor<PatientOptions> _optionsAccessor;
1919

2020
public PatientController(IHttpClientFactory httpClientFactory,
2121
IOptionsMonitor<PatientOptions> optionsAccessor)
2222
{
2323
_httpClientFactory = httpClientFactory;
24-
_patientOptions = optionsAccessor.CurrentValue;
24+
_optionsAccessor = optionsAccessor;
2525
}
2626

2727
public async Task<IActionResult> Index()
2828
{
2929
HttpClient httpClient = _httpClientFactory.CreateClient();
30-
HttpResponseMessage patientApiResponseMessage = await httpClient.GetAsync(_patientOptions.PatientGatewayUrl);
30+
HttpResponseMessage patientApiResponseMessage = await httpClient.GetAsync(_optionsAccessor.CurrentValue.PatientGatewayUrl);
3131
if (patientApiResponseMessage.IsSuccessStatusCode)
3232
{
3333
using Stream patientApiResponseStream = await patientApiResponseMessage.Content.ReadAsStreamAsync();
@@ -51,7 +51,7 @@ public async Task<IActionResult> Details(int? id)
5151
return RedirectToAction(nameof(Index));
5252
}
5353
HttpClient httpClient = _httpClientFactory.CreateClient();
54-
var patientGetByIdGatewayUrl = $"{_patientOptions.PatientGatewayUrl}/{id}";
54+
var patientGetByIdGatewayUrl = $"{_optionsAccessor.CurrentValue.PatientGatewayUrl}/{id}";
5555
HttpResponseMessage patientApiResponseMessage = await httpClient.GetAsync(patientGetByIdGatewayUrl);
5656
if (patientApiResponseMessage.StatusCode == HttpStatusCode.OK)
5757
{
@@ -73,7 +73,7 @@ public async Task<IActionResult> Create(PatientModel patient)
7373
{
7474
HttpClient httpClient = _httpClientFactory.CreateClient();
7575
var patientContent = new StringContent(JsonSerializer.Serialize(patient), Encoding.UTF8, "application/json");
76-
HttpResponseMessage patientApiResponseMessage = await httpClient.PostAsync(_patientOptions.PatientGatewayUrl, patientContent);
76+
HttpResponseMessage patientApiResponseMessage = await httpClient.PostAsync(_optionsAccessor.CurrentValue.PatientGatewayUrl, patientContent);
7777
if (patientApiResponseMessage.IsSuccessStatusCode)
7878
{
7979
return RedirectToAction(nameof(Index));
@@ -88,7 +88,7 @@ public async Task<IActionResult> Edit(int? id)
8888
return RedirectToAction(nameof(Index));
8989
}
9090
HttpClient httpClient = _httpClientFactory.CreateClient();
91-
var patientGetByIdGatewayUrl = $"{_patientOptions.PatientGatewayUrl}/{id}";
91+
var patientGetByIdGatewayUrl = $"{_optionsAccessor.CurrentValue.PatientGatewayUrl}/{id}";
9292
HttpResponseMessage patientApiResponseMessage = await httpClient.GetAsync(patientGetByIdGatewayUrl);
9393
if (patientApiResponseMessage.StatusCode == HttpStatusCode.OK)
9494
{
@@ -104,7 +104,7 @@ public async Task<IActionResult> Edit(int? id)
104104
public async Task<IActionResult> Edit(int id, PatientModel patient)
105105
{
106106
HttpClient httpClient = _httpClientFactory.CreateClient();
107-
var patientUpdateGatewayUrl = $"{_patientOptions.PatientGatewayUrl}/{id}";
107+
var patientUpdateGatewayUrl = $"{_optionsAccessor.CurrentValue.PatientGatewayUrl}/{id}";
108108
var patientContent = new StringContent(JsonSerializer.Serialize(patient), Encoding.UTF8, "application/json");
109109
HttpResponseMessage patientApiResponseMessage = await httpClient.PutAsync(patientUpdateGatewayUrl, patientContent);
110110
if (patientApiResponseMessage.IsSuccessStatusCode)
@@ -117,7 +117,7 @@ public async Task<IActionResult> Edit(int id, PatientModel patient)
117117
public async Task<IActionResult> Delete(int? id)
118118
{
119119
HttpClient httpClient = _httpClientFactory.CreateClient();
120-
var patientDeleteGatewayUrl = $"{_patientOptions.PatientGatewayUrl}/{id}";
120+
var patientDeleteGatewayUrl = $"{_optionsAccessor.CurrentValue.PatientGatewayUrl}/{id}";
121121
HttpResponseMessage patientApiResponseMessage = await httpClient.DeleteAsync(patientDeleteGatewayUrl);
122122
if (patientApiResponseMessage.IsSuccessStatusCode)
123123
{

src/Gateways/WebGateway/GrpcClients/Consultations/ConsultationGrpcClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace MedicalSystem.Gateways.WebGateway.GrpcClients.Consultations
99
{
1010
public class ConsultationGrpcClient : IConsultationGrpcClient
1111
{
12-
private readonly ConsultationOptions _consultationOptions;
12+
private readonly IOptionsMonitor<ConsultationOptions> _optionsAccessor;
1313
private readonly Consultation.ConsultationClient _client;
1414

1515
public ConsultationGrpcClient(IOptionsMonitor<ConsultationOptions> optionsAccessor)
1616
{
17-
_consultationOptions = optionsAccessor.CurrentValue;
17+
_optionsAccessor = optionsAccessor;
1818
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
19-
GrpcChannel channel = GrpcChannel.ForAddress(_consultationOptions.ConsultationApiUrl);
19+
GrpcChannel channel = GrpcChannel.ForAddress(_optionsAccessor.CurrentValue.ConsultationApiUrl);
2020
_client = new Consultation.ConsultationClient(channel);
2121
}
2222

src/Gateways/WebGateway/GrpcClients/Consultations/DoctorGrpcClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace MedicalSystem.Gateways.WebGateway.GrpcClients.Consultations
99
{
1010
public class DoctorGrpcClient : IDoctorGrpcClient
1111
{
12-
private readonly ConsultationOptions _consultationOptions;
12+
private readonly IOptionsMonitor<ConsultationOptions> _optionsAccessor;
1313
private readonly Doctor.DoctorClient _client;
1414

1515
public DoctorGrpcClient(IOptionsMonitor<ConsultationOptions> optionsAccessor)
1616
{
17-
_consultationOptions = optionsAccessor.CurrentValue;
17+
_optionsAccessor = optionsAccessor;
1818
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
19-
GrpcChannel channel = GrpcChannel.ForAddress(_consultationOptions.ConsultationApiUrl);
19+
GrpcChannel channel = GrpcChannel.ForAddress(_optionsAccessor.CurrentValue.ConsultationApiUrl);
2020
_client = new Doctor.DoctorClient(channel);
2121
}
2222

src/Gateways/WebGateway/GrpcClients/Consultations/PatientGrpcClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace MedicalSystem.Gateways.WebGateway.GrpcClients.Consultations
99
{
1010
public class PatientGrpcClient : IPatientGrpcClient
1111
{
12-
private readonly ConsultationOptions _consultationOptions;
12+
private readonly IOptionsMonitor<ConsultationOptions> _optionsAccessor;
1313
private readonly Patient.PatientClient _client;
1414

1515
public PatientGrpcClient(IOptionsMonitor<ConsultationOptions> optionsAccessor)
1616
{
17-
_consultationOptions = optionsAccessor.CurrentValue;
17+
_optionsAccessor = optionsAccessor;
1818
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
19-
GrpcChannel channel = GrpcChannel.ForAddress(_consultationOptions.ConsultationApiUrl);
19+
GrpcChannel channel = GrpcChannel.ForAddress(_optionsAccessor.CurrentValue.ConsultationApiUrl);
2020
_client = new Patient.PatientClient(channel);
2121
}
2222

src/Gateways/WebGateway/GrpcClients/Doctors/DoctorGrpcClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace MedicalSystem.Gateways.WebGateway.GrpcClients.Doctors
99
{
1010
public class DoctorGrpcClient : IDoctorGrpcClient
1111
{
12-
private readonly DoctorOptions _doctorOptions;
12+
private readonly IOptionsMonitor<DoctorOptions> _optionsAccessor;
1313
private readonly Doctor.DoctorClient _client;
1414

1515
public DoctorGrpcClient(IOptionsMonitor<DoctorOptions> optionsAccessor)
1616
{
17-
_doctorOptions = optionsAccessor.CurrentValue;
17+
_optionsAccessor = optionsAccessor;
1818
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
19-
GrpcChannel channel = GrpcChannel.ForAddress(_doctorOptions.DoctorApiUrl);
19+
GrpcChannel channel = GrpcChannel.ForAddress(_optionsAccessor.CurrentValue.DoctorApiUrl);
2020
_client = new Doctor.DoctorClient(channel);
2121
}
2222

src/Gateways/WebGateway/GrpcClients/Patients/PatientGrpcClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace MedicalSystem.Gateways.WebGateway.GrpcClients.Patients
99
{
1010
public class PatientGrpcClient : IPatientGrpcClient
1111
{
12-
private readonly PatientOptions _patientOptions;
12+
private readonly IOptionsMonitor<PatientOptions> _optionsAccessor;
1313
private readonly Patient.PatientClient _client;
1414

1515
public PatientGrpcClient(IOptionsMonitor<PatientOptions> optionsAccessor)
1616
{
17-
_patientOptions = optionsAccessor.CurrentValue;
17+
_optionsAccessor = optionsAccessor;
1818
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
19-
GrpcChannel channel = GrpcChannel.ForAddress(_patientOptions.PatientApiUrl);
19+
GrpcChannel channel = GrpcChannel.ForAddress(_optionsAccessor.CurrentValue.PatientApiUrl);
2020
_client = new Patient.PatientClient(channel);
2121
}
2222

0 commit comments

Comments
 (0)