|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 | 4 | using Microsoft.AspNetCore.Components.Authorization;
|
5 |
| -using Microsoft.AspNetCore.Components.Web; |
6 | 5 | using Microsoft.Extensions.Options;
|
7 | 6 |
|
8 | 7 | namespace Microsoft.AspNetCore.Components.WebAssembly.Server;
|
9 | 8 |
|
10 |
| -internal sealed class AuthenticationStateSerializer : IHostEnvironmentAuthenticationStateProvider, IDisposable |
| 9 | +internal sealed class AuthenticationStateSerializer : IHostEnvironmentAuthenticationStateProvider |
11 | 10 | {
|
12 | 11 | // Do not change. This must match all versions of the server-side DeserializedAuthenticationStateProvider.PersistenceKey.
|
13 | 12 | internal const string PersistenceKey = $"__internal__{nameof(AuthenticationState)}";
|
14 | 13 |
|
15 |
| - private readonly PersistentComponentState _state; |
16 | 14 | private readonly Func<AuthenticationState, ValueTask<AuthenticationStateData?>> _serializeCallback;
|
17 |
| - private readonly PersistingComponentStateSubscription _subscription; |
18 | 15 |
|
19 | 16 | private Task<AuthenticationState>? _authenticationStateTask;
|
20 | 17 | private AuthenticationStateData? _authenticationStateData;
|
21 | 18 |
|
22 |
| - [PersistentComponentStateStore] |
| 19 | + [SupplyParameterFromPersistentComponentState] |
23 | 20 | public AuthenticationStateData? AuthStateData
|
24 | 21 | {
|
25 | 22 | get => _authenticationStateData;
|
26 | 23 | set => _authenticationStateData = value;
|
27 | 24 | }
|
28 | 25 |
|
29 |
| - public AuthenticationStateSerializer(PersistentComponentState persistentComponentState, IOptions<AuthenticationStateSerializationOptions> options) |
| 26 | + public AuthenticationStateSerializer(IOptions<AuthenticationStateSerializationOptions> options) |
30 | 27 | {
|
31 |
| - _state = persistentComponentState; |
32 | 28 | _serializeCallback = options.Value.SerializationCallback;
|
33 |
| - _subscription = persistentComponentState.RegisterOnPersisting(OnPersistingAsync, RenderMode.InteractiveWebAssembly); |
34 |
| - } |
35 |
| - |
36 |
| - private async Task OnPersistingAsync() |
37 |
| - { |
38 |
| - if (_authenticationStateTask is null) |
39 |
| - { |
40 |
| - throw new InvalidOperationException($"{nameof(SetAuthenticationState)} must be called before the {nameof(PersistentComponentState)}.{nameof(PersistentComponentState.RegisterOnPersisting)} callback."); |
41 |
| - } |
42 |
| - |
43 |
| - AuthStateData = await _serializeCallback(await _authenticationStateTask); |
44 | 29 | }
|
45 | 30 |
|
46 | 31 | /// <inheritdoc />
|
47 |
| - public void SetAuthenticationState(Task<AuthenticationState> authenticationStateTask) |
| 32 | + public async void SetAuthenticationState(Task<AuthenticationState> authenticationStateTask) |
48 | 33 | {
|
49 | 34 | _authenticationStateTask = authenticationStateTask ?? throw new ArgumentNullException(nameof(authenticationStateTask));
|
50 |
| - } |
51 |
| - |
52 |
| - public void Dispose() |
53 |
| - { |
54 |
| - _subscription.Dispose(); |
| 35 | + |
| 36 | + if (_authenticationStateTask is not null) |
| 37 | + { |
| 38 | + AuthStateData = await _serializeCallback(await _authenticationStateTask); |
| 39 | + } |
55 | 40 | }
|
56 | 41 | }
|
0 commit comments