Skip to content

Commit

Permalink
bff - Split StateProviderPollingInterval into separate options for WA…
Browse files Browse the repository at this point in the history
…SM and Server
  • Loading branch information
Erwinvandervalk committed Feb 11, 2025
1 parent cfc54f0 commit 106b8c8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
7 changes: 6 additions & 1 deletion bff/docs/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ a custom IAccessTokenRetriever, then you should adjust their usage accordingly.

### AddAddEntityFrameworkServerSideSessionsServices has been renamed to AddEntityFrameworkServerSideSessionsServices

If you used the method AddAddEntityFrameworkServerSideSessionsServices() in your code, please replace it with the corrected AddEntityFrameworkServerSideSessionsServices()
If you used the method AddAddEntityFrameworkServerSideSessionsServices() in your code, please replace it with the corrected AddEntityFrameworkServerSideSessionsServices()

### StateProviderPollingDelay and StateProviderPollingInterval have been split into separate options for WebAssembly and Server.

If you used BffBlazorOptions.StateProviderPollingInterval or BffBlazorOptions.StateProviderPollingDelay to configure different polling settings, you should now consider if this same setting applies to either Server, WASM or both. Set the appropriate properties accordingly.

21 changes: 17 additions & 4 deletions bff/src/Bff.Blazor.Client/BffBlazorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,28 @@ public class BffBlazorOptions
public string? StateProviderBaseAddress { get; set; } = null;

/// <summary>
/// The delay, in milliseconds, before the AuthenticationStateProvider will
/// The delay, in milliseconds, before the BffClientAuthenticationStateProvider will
/// start polling the /bff/user endpoint. Defaults to 1000 ms.
/// </summary>
public int StateProviderPollingDelay { get; set; } = 1000;
public int WebAssemblyStateProviderPollingDelay { get; set; } = 1000;

/// <summary>
/// The delay, in milliseconds, between polling requests by the
/// AuthenticationStateProvider to the /bff/user endpoint. Defaults to 5000
/// BffClientAuthenticationStateProvider to the /bff/user endpoint. Defaults to 5000
/// ms.
/// </summary>
public int StateProviderPollingInterval { get; set; } = 5000;
public int WebAssemblyStateProviderPollingInterval { get; set; } = 5000;

/// <summary>
/// The delay, in milliseconds, before the BffServerAuthenticationStateProvider will
/// start polling the /bff/user endpoint. Defaults to 1000 ms.
/// </summary>
public int ServerStateProviderPollingDelay { get; set; } = 1000;

/// <summary>
/// The delay, in milliseconds, between polling requests by the
/// BffServerAuthenticationStateProvider to the /bff/user endpoint. Defaults to 5000
/// ms.
/// </summary>
public int ServerStateProviderPollingInterval { get; set; } = 5000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ async void TimerCallback(object? _)

timer = _timeProvider.CreateTimer(TimerCallback,
null,
TimeSpan.FromMilliseconds(_options.StateProviderPollingDelay),
TimeSpan.FromMilliseconds(_options.StateProviderPollingInterval));
TimeSpan.FromMilliseconds(_options.WebAssemblyStateProviderPollingDelay),
TimeSpan.FromMilliseconds(_options.WebAssemblyStateProviderPollingInterval));
}
return state;
}
Expand Down
2 changes: 1 addition & 1 deletion bff/src/Bff.Blazor.Client/Internals/GetUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void InitializeCache()
public async ValueTask<ClaimsPrincipal> GetUserAsync(bool useCache = true)
{
var now = _timeProvider.GetUtcNow();
if (useCache && now < _userLastCheck.AddMilliseconds(_options.StateProviderPollingDelay))
if (useCache && now < _userLastCheck.AddMilliseconds(_options.WebAssemblyStateProviderPollingDelay))
{
_logger.LogDebug("Taking user from cache");
return _cachedUser;
Expand Down
3 changes: 1 addition & 2 deletions bff/src/Bff.Blazor/BffServerAuthenticationStateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public BffServerAuthenticationStateProvider(
_bffOptions = bffOptions.Value;
_logger = loggerFactory.CreateLogger<BffServerAuthenticationStateProvider>();

// TODO - Consider separate options for server and client
RevalidationInterval = TimeSpan.FromMilliseconds(blazorOptions.Value.StateProviderPollingInterval);
RevalidationInterval = TimeSpan.FromMilliseconds(blazorOptions.Value.ServerStateProviderPollingInterval);

AuthenticationStateChanged += OnAuthenticationStateChanged;
_subscription = _state.RegisterOnPersisting(OnPersistingAsync, RenderMode.InteractiveWebAssembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public async Task after_configured_delay_UserService_is_called_again_and_state_n
time,
TestMocks.MockOptions(new BffBlazorOptions
{
StateProviderPollingDelay = 2000,
StateProviderPollingInterval = 10000
WebAssemblyStateProviderPollingDelay = 2000,
WebAssemblyStateProviderPollingInterval = 10000

}),
Substitute.For<ILogger<BffClientAuthenticationStateProvider>>());
Expand Down Expand Up @@ -122,8 +122,8 @@ public async Task timer_stops_when_user_logs_out()
time,
TestMocks.MockOptions(new BffBlazorOptions
{
StateProviderPollingDelay = 2000,
StateProviderPollingInterval = 10000
ServerStateProviderPollingDelay = 2000,
ServerStateProviderPollingInterval = 10000

}),
Substitute.For<ILogger<BffClientAuthenticationStateProvider>>());
Expand Down

0 comments on commit 106b8c8

Please sign in to comment.