-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible fix for .NET 8 Blazor Web App breakage #481
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3d0e703
Update to .NET 8
WhitWaldo b9be89e
Initializing store from OnInitializedAsync instead of OnAfterRenderAs…
WhitWaldo ffb3a3e
Added .NET 8-specific preprocessor regions
WhitWaldo d3308bd
Added fixes identified in #481 comments
WhitWaldo a3916d6
Adding persistence implementation
WhitWaldo 894a244
Added a few missing items
WhitWaldo 0f337a9
Updated to resolve flicker
WhitWaldo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Source/Lib/Fluxor.Blazor.Web/Persistence/PersistenceEffects.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Fluxor.Persistence; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fluxor.Blazor.Web.Persistence | ||
{ | ||
#if NET6_0_OR_GREATER | ||
public sealed class PersistenceEffects | ||
{ | ||
private readonly IPersistenceManager _persistenceManager; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public PersistenceEffects(IPersistenceManager persistenceManager, IServiceProvider serviceProvider) | ||
{ | ||
_persistenceManager = persistenceManager; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
/// <summary> | ||
/// Maintains a reference to IStore - injected this way to avoid a circular dependency during the effect method registration | ||
/// </summary> | ||
private readonly Lazy<IStore> _store = new(_serviceProvider.GetRequiredService<IStore>); | ||
|
||
[EffectMethod(typeof(StorePersistingAction))] | ||
public async Task PersistStoreData(IDispatcher dispatcher) | ||
{ | ||
//Serialize the store | ||
var json = _store.Value.SerializeToJson(); | ||
|
||
//Save to the persistence manager | ||
await _persistenceManager.PersistStoreToStateAsync(json); | ||
|
||
//Completed | ||
dispatcher.Dispatch(new StorePersistedAction()); | ||
} | ||
|
||
[EffectMethod(typeof(StoreRehydratingAction))] | ||
public async Task RehydrateStoreData(IDispatcher dispatcher) | ||
{ | ||
//Read from the persistence manager | ||
var serializedStore = await _persistenceManager.RehydrateStoreFromStateAsync(); | ||
if (serializedStore is null) | ||
{ | ||
//Nothing to rehydrate - leave as-is | ||
dispatcher.Dispatch(new StoreRehydratedAction()); | ||
return; | ||
} | ||
|
||
_store.Value.RehydrateFromJson(serializedStore); | ||
|
||
//Completed | ||
dispatcher.Dispatch(new StoreRehydratedAction()); | ||
} | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#nullable enable | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fluxor.Persistence | ||
{ | ||
public interface IPersistenceManager | ||
{ | ||
/// <summary> | ||
/// Persists the store to a persisted state. | ||
/// </summary> | ||
/// <param name="serializedStore">The serialized store data being persisted.</param> | ||
public Task PersistStoreToStateAsync(string serializedStore); | ||
|
||
/// <summary> | ||
/// Rehydrates the store from a persisted state. | ||
/// </summary> | ||
public Task<string?> RehydrateStoreFromStateAsync(); | ||
|
||
/// <summary> | ||
/// Clears the store from the persisted state. | ||
/// </summary> | ||
public Task ClearStoreFromStateAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fluxor.Persistence | ||
{ | ||
public sealed class PersistenceEffects | ||
{ | ||
private readonly IPersistenceManager _persistenceManager; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public PersistenceEffects(IPersistenceManager persistenceManager, IServiceProvider serviceProvider) | ||
{ | ||
_persistenceManager = persistenceManager; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
/// <summary> | ||
/// Maintains a reference to IStore - injected this way to avoid a circular dependency during the effect method registration | ||
/// </summary> | ||
private readonly Lazy<IStore> _store = new(_serviceProvider.GetRequiredService<IStore>); | ||
|
||
[EffectMethod(typeof(StorePersistingAction))] | ||
public async Task PersistStoreData(IDispatcher dispatcher) | ||
{ | ||
//Serialize the store | ||
var json = _store.Value.SerializeToJson(); | ||
|
||
//Save to the persistence manager | ||
await _persistenceManager.PersistStoreToStateAsync(json); | ||
|
||
//Completed | ||
dispatcher.Dispatch(new StorePersistedAction()); | ||
} | ||
|
||
[EffectMethod(typeof(StoreRehydratingAction))] | ||
public async Task RehydrateStoreData(IDispatcher dispatcher) | ||
{ | ||
//Read from the persistence manager | ||
var serializedStore = await _persistenceManager.RehydrateStoreFromStateAsync(); | ||
if (serializedStore is null) | ||
{ | ||
//Nothing to rehydrate - leave as-is | ||
dispatcher.Dispatch(new StoreRehydratedAction()); | ||
return; | ||
} | ||
|
||
_store.Value.RehydrateFromJson(serializedStore); | ||
|
||
//Completed | ||
dispatcher.Dispatch(new StoreRehydratedAction()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Fluxor.Persistence | ||
{ | ||
/// <summary> | ||
/// Dispatched by the store once it has been successfully persisted to state. | ||
/// </summary> | ||
public sealed class StorePersistedAction | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Fluxor.Persistence | ||
{ | ||
/// <summary> | ||
/// Dispatched by the store once it has started persisting to state. | ||
/// </summary> | ||
public sealed class StorePersistingAction | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Fluxor.Persistence | ||
{ | ||
/// <summary> | ||
/// Dispatched by the store once it has been successfully rehydrated from state. | ||
/// </summary> | ||
public sealed class StoreRehydratedAction | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Fluxor.Persistence | ||
{ | ||
/// <summary> | ||
/// Dispatched by the store once it has started rehydrating from state. | ||
/// </summary> | ||
public sealed class StoreRehydratingAction | ||
{ | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.0
does this need to be removed or a condition added for!= 'net8.0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rather assumed that whatever was there was compatible up to the current supported build prior to my adding .NET 8 to the list - presumably that includes .NET Core 3.1 as-is if that's still a supported target, so I wouldn't think anything else is necessary.