From a7092ec70511f1894151c19dd66139a71c763be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Ko=C5=BEelj?= Date: Fri, 20 Jan 2023 10:36:53 +0100 Subject: [PATCH] Add base route configuration support to TaxRateService --- .../TaxRates/TaxRateService.cs | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Connected.Common.Types.Client/TaxRates/TaxRateService.cs b/src/Connected.Common.Types.Client/TaxRates/TaxRateService.cs index 638815c..21f5123 100644 --- a/src/Connected.Common.Types.Client/TaxRates/TaxRateService.cs +++ b/src/Connected.Common.Types.Client/TaxRates/TaxRateService.cs @@ -1,4 +1,5 @@ using System.Collections.Immutable; +using Connected.Configuration; using Connected.Net; using Connected.Remote; using Connected.ServiceModel; @@ -10,47 +11,62 @@ namespace Connected.Common.Types.TaxRates; /// This is the client implementation of the . /// internal class TaxRateService : EntityService, ITaxRateService, IRemoteService -{ - public TaxRateService(IHttpService http) +{ + public TaxRateService(IHttpService http, IConfigurationService configurationService) { Http = http; + ConfigurationService = configurationService; } private IHttpService Http { get; } + private IConfigurationService ConfigurationService { get; } + + private string GetBaseAddress() + { + var serviceConfigurations = ConfigurationService.Remote.Query(nameof(TaxRateService)); + + foreach (var configuration in serviceConfigurations) + { + if (!string.IsNullOrWhiteSpace(configuration?.Address)) + return configuration.Address; + } + + throw new Exception("No base address registered for TaxRateService"); + } public async Task Delete(PrimaryKeyArgs e) { - await Http.Post("http://localhost:5063/management/commonTypes/taxRates/delete", e); + await Http.Post($"{GetBaseAddress()}/management/commonTypes/taxRates/delete", e); } public async Task Insert(InsertTaxRateArgs e) { - return await Http.Post("http://localhost:5063/management/commonTypes/taxRates/insert", e); + return await Http.Post($"{GetBaseAddress()}/management/commonTypes/taxRates/insert", e); } public async Task?> Query(PrimaryKeyListArgs e) { - return (await Http.Post?>("http://localhost:5063/management/commonTypes/taxRates/select", e)).ToImmutableList(); + return (await Http.Post?>($"{GetBaseAddress()}/management/commonTypes/taxRates/select", e))?.ToImmutableList() ?? ImmutableList.Empty; } public async Task?> Query(QueryArgs? args) { - return (await Http.Post?>("http://localhost:5063/management/commonTypes/taxRates/query", args ?? QueryArgs.NoPaging)).ToImmutableList(); + return (await Http.Post?>($"{GetBaseAddress()}/management/commonTypes/taxRates/query", args ?? QueryArgs.NoPaging))?.ToImmutableList() ?? ImmutableList.Empty; } public async Task Select(PrimaryKeyArgs e) { - return await Http.Post("http://localhost:5063/management/commonTypes/taxRates/select", e); + return await Http.Post($"{GetBaseAddress()}/management/commonTypes/taxRates/select", e); } public async Task Select(TaxRateArgs e) { - return await Http.Post("http://localhost:5063/management/commonTypes/taxRates/select", e); + return await Http.Post($"{GetBaseAddress()}/management/commonTypes/taxRates/select", e); } public async Task Update(UpdateTaxRateArgs e) { - await Http.Post("http://localhost:5063/management/commonTypes/taxRates/update", e); + await Http.Post($"{GetBaseAddress()}/management/commonTypes/taxRates/update", e); } }