diff --git a/src/Money.UI.Blazor/Services/ApiHubService.cs b/src/Money.UI.Blazor/Services/ApiHubService.cs index c4e33eae..0b30e2a7 100644 --- a/src/Money.UI.Blazor/Services/ApiHubService.cs +++ b/src/Money.UI.Blazor/Services/ApiHubService.cs @@ -1,5 +1,5 @@ using Microsoft.AspNetCore.SignalR.Client; -using Microsoft.JSInterop; +using Microsoft.Extensions.Options; using Neptuo; using Neptuo.Events; using Neptuo.Exceptions; @@ -18,33 +18,39 @@ public class ApiHubService private readonly BrowserEventDispatcher events; private readonly BrowserExceptionHandler exceptions; private readonly Navigator navigator; + private readonly ApiClientConfiguration apiConfiguration; + private readonly TokenContainer token; private readonly ILog log; private HubConnection connection; public bool IsStarted { get; private set; } - public ApiHubService(BrowserEventDispatcher events, BrowserExceptionHandler exceptions, Navigator navigator, ILogFactory logFactory) + public ApiHubService(BrowserEventDispatcher events, BrowserExceptionHandler exceptions, Navigator navigator, IOptions apiConfiguration, TokenContainer token, ILogFactory logFactory) { Ensure.NotNull(events, "events"); Ensure.NotNull(exceptions, "exceptions"); Ensure.NotNull(navigator, "navigator"); + Ensure.NotNull(apiConfiguration, "apiConfiguration"); + Ensure.NotNull(token, "token"); Ensure.NotNull(logFactory, "logFactory"); this.events = events; this.exceptions = exceptions; this.navigator = navigator; + this.apiConfiguration = apiConfiguration.Value; + this.token = token; this.log = logFactory.Scope("ApiHub"); } - public async Task StartAsync(string url, string token) + public async Task StartAsync() { await StopAsync(); - log.Debug($"Connecting with token '{token}'."); + log.Debug($"Connecting with token '{token.Value}'."); - url = $"{url}?access_token={token}"; + string url = $"{apiConfiguration.ApiUrl}api?access_token={token.Value}"; connection = new HubConnectionBuilder() - .WithUrl(url, o => o.AccessTokenProvider = () => Task.FromResult(token)) + .WithUrl(url, o => o.AccessTokenProvider = () => Task.FromResult(token.Value)) .Build(); connection.On("RaiseEvent", payload => diff --git a/src/Money.UI.Blazor/Services/SignalRListener.cs b/src/Money.UI.Blazor/Services/SignalRListener.cs index 4f41f355..4a1c019d 100644 --- a/src/Money.UI.Blazor/Services/SignalRListener.cs +++ b/src/Money.UI.Blazor/Services/SignalRListener.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Options; -using Money.Events; +using Money.Events; using Neptuo; using Neptuo.Events.Handlers; using System; @@ -14,21 +13,15 @@ namespace Money.Services public class SignalRListener : IEventHandler, IEventHandler { private readonly ApiHubService apiHub; - private readonly ApiClientConfiguration apiConfiguration; - private readonly TokenContainer token; - public SignalRListener(ApiHubService apiHub, IOptions apiConfiguration, TokenContainer token) + public SignalRListener(ApiHubService apiHub) { Ensure.NotNull(apiHub, "apiHub"); - Ensure.NotNull(apiConfiguration, "apiConfiguration"); - Ensure.NotNull(token, "token"); this.apiHub = apiHub; - this.apiConfiguration = apiConfiguration.Value; - this.token = token; } Task IEventHandler.HandleAsync(UserSignedIn payload) - => apiHub.StartAsync(apiConfiguration.ApiUrl.ToString() + "api", token.Value); + => apiHub.StartAsync(); Task IEventHandler.HandleAsync(UserSignedOut payload) => apiHub.StopAsync();