Skip to content

Commit

Permalink
Merge pull request #23 from le-nn/migrate_to_net8.0
Browse files Browse the repository at this point in the history
Migrate to net8.0
  • Loading branch information
le-nn authored Nov 21, 2023
2 parents 06354a9 + 91604a9 commit f541735
Show file tree
Hide file tree
Showing 38 changed files with 87 additions and 83 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ csharp_style_prefer_utf8_string_literals = true:warning
csharp_style_prefer_readonly_struct = true:warning
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
Expand Down Expand Up @@ -295,4 +297,5 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:sil
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_event = false:silent
dotnet_style_prefer_collection_expression = true:warning
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.x
dotnet-version: 8.x

# Generate the website
- name: Install wasm tool
Expand Down
1 change: 1 addition & 0 deletions Memento.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{E9CA5D2D
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
.github\workflows\build-and-deploy.yml = .github\workflows\build-and-deploy.yml
src\Directory.Build.props = src\Directory.Build.props
README.md = README.md
EndProjectSection
Expand Down
6 changes: 3 additions & 3 deletions samples/Memento.Sample.Blazor/Memento.Sample.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<StaticWebAssetBasePath>/</StaticWebAssetBasePath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Memento.Core.History;
using Memento.Sample.Blazor.Todos;
using System.Collections.Immutable;

Expand Down
1 change: 0 additions & 1 deletion samples/Memento.Sample.Blazor/Stores/RedoUndoTodoStore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Memento.Core.History;
using Memento.Sample.Blazor.Todos;
using System.Collections.Immutable;

Expand Down
6 changes: 5 additions & 1 deletion samples/Memento.Sample.BlazorServer/LoggerMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public LoggerMiddlewareHandler(IJSRuntime jSRuntime) {
/// <param name="e">The state change event arguments.</param>
/// <param name="next">The next middleware in the pipeline.</param>
/// <returns>The updated state after processing by the middleware pipeline.</returns>
public override RootState? HandleProviderDispatch(RootState? state, IStateChangedEventArgs<object, Command> e, NextProviderMiddlewareCallback next) {
public override RootState? HandleProviderDispatch(
RootState? state,
IStateChangedEventArgs<object, Command> e,
NextProviderMiddlewareCallback next
) {
_ = HandleLog(state, e);
return next(state, e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions samples/Memento.Sample.BlazorServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
var builder = WebApplication.CreateBuilder(args);

builder.Services
.AddRemoteReduxDevToolMiddleware()
.AddMemento()
.AddRemoteReduxDevToolMiddleware(true)
.AddMemento(true)
.AddMiddleware(() => new LoggerMiddleware())
.ScanAssemblyAndAddStores(typeof(App).Assembly);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<RunAOTCompilation>true</RunAOTCompilation>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
<PackageReference Include="PublishSPAforGitHubPages.Build" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="PublishSPAforGitHubPages.Build" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Memento.Sample.BlazorWasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.AddBrowserReduxDevToolMiddleware(new() {
StackTraceEnabled = true,
OpenDevTool = true,

})
.ScanAssemblyAndAddStores(typeof(App).Assembly);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Memento.Blazor/ComponentUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static IEnumerable<PropertyInfo> GetStateChangedNotifierProperties(Type
: GetStateChangedNotifierProperties(t.BaseType!)
.Union(
t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
.Where(p => typeof(IStore<object,Command>).IsAssignableFrom(p.PropertyType))
.Where(p => typeof(IStore<object, Command>).IsAssignableFrom(p.PropertyType))
);

private static IEnumerable<GetStateChangedPropertyDelegate> GetStateChangedNotifierPropertyDelegatesForType(Type type)
Expand Down
6 changes: 5 additions & 1 deletion src/Memento.Blazor/Memento.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.*" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.AspNetCore.Components" Version="7.*" />
Expand Down
12 changes: 6 additions & 6 deletions src/Memento.Blazor/StoreConfigExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public static IServiceCollection AddMemento(this IServiceCollection services, bo
/// <param name="isScoped">If true, registers the store with a scoped lifetime. Otherwise, registers with a singleton lifetime.</param>
/// <returns>>The registered IServiceCollection instance from the IServiceCollection.</returns>
public static IServiceCollection AddStore<TStore>(this IServiceCollection collection, bool isScoped = true)
where TStore : class, IStore<object,Command> {
where TStore : class, IStore<object, Command> {
if (isScoped) {
collection.AddScoped<TStore>()
.AddScoped< IStore<object,Command>>(p => p.GetRequiredService<TStore>());
.AddScoped<IStore<object, Command>>(p => p.GetRequiredService<TStore>());
}
else {
collection.AddSingleton<TStore>()
.AddSingleton< IStore<object,Command>>(p => p.GetRequiredService<TStore>());
.AddSingleton<IStore<object, Command>>(p => p.GetRequiredService<TStore>());
}
return collection;
}
Expand All @@ -47,14 +47,14 @@ public static IServiceCollection AddStore<TStore>(this IServiceCollection collec
/// <param name="isScoped">If true, registers the stores with a scoped lifetime. Otherwise, registers with a singleton lifetime.</param>
/// <returns>>The registered IServiceCollection instance from the IServiceCollection.</returns>
public static void ScanAssemblyAndAddStores(this IServiceCollection services, Assembly assembly, bool isScoped = true) {
foreach (var type in assembly.GetTypes().Where(t => t.IsAssignableTo(typeof( IStore<object,Command>)))) {
foreach (var type in assembly.GetTypes().Where(t => t.IsAssignableTo(typeof(IStore<object, Command>)))) {
if (isScoped) {
services.AddScoped(type)
.AddScoped(p => ( IStore<object,Command>)p.GetRequiredService(type));
.AddScoped(p => (IStore<object, Command>)p.GetRequiredService(type));
}
else {
services.AddSingleton(type)
.AddSingleton(p => ( IStore<object,Command>)p.GetRequiredService(type));
.AddSingleton(p => (IStore<object, Command>)p.GetRequiredService(type));
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Memento.Blazor/StoreObeserver.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace Memento.Core;

internal class StoreObserver
Expand Down
5 changes: 0 additions & 5 deletions src/Memento.Core/AbstractMementoStore.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Memento.Core.History;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Memento.Core;

Expand Down
2 changes: 0 additions & 2 deletions src/Memento.Core/AbstractStore.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Memento.Core.Internals;
using System.Collections.Concurrent;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Data;

namespace Memento.Core;

Expand Down
1 change: 0 additions & 1 deletion src/Memento.Core/Executors/ThrottledExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Memento.Core.Internals;
using System;
using System.Collections.Concurrent;

namespace Memento.Core.Executors;
Expand Down
2 changes: 1 addition & 1 deletion src/Memento.Core/History/FutureHistoryStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public IReadOnlyCollection<T> CloneAsReadOnly() {

public void Push(T item) {
lock (_values) {
_values.Insert(0, item);
_values.Insert(0, item);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Memento.Core/History/IHistoryItem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Memento.Core.History;

public interface IHistoryItem<out T> {
public interface IHistoryItem<out T> {
string Name { get; }

T HistoryState { get; }
Expand Down
6 changes: 3 additions & 3 deletions src/Memento.Core/Internals/StoreObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public void OnNext(T value) {
}

internal class StoreObserver<TState, TCommand>
: IObserver<IStateChangedEventArgs<TState, TCommand>>
where TState:class
where TCommand :Command {
: IObserver<IStateChangedEventArgs<TState, TCommand>>
where TState : class
where TCommand : Command {
readonly Action<IStateChangedEventArgs<TState, TCommand>> _action;

public StoreObserver(Action<IStateChangedEventArgs<TState, TCommand>> action) {
Expand Down
7 changes: 5 additions & 2 deletions src/Memento.Core/Middleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ public abstract class Middleware : IDisposable {
public MiddlewareHandler Handler => _handler
?? throw new InvalidOperationException($"Middleware '{GetType().FullName}' has not initialized.");

internal async Task InitializeAsync(IServiceProvider provider) {
internal void Initalize(IServiceProvider provider) {
var handler = Create(provider);
_handler = handler;
await handler.InitializedAsync();
}

internal async Task InvokeInitializedAsync() {
await Handler.InitializedAsync();
}

protected abstract MiddlewareHandler Create(IServiceProvider provider);
Expand Down
2 changes: 1 addition & 1 deletion src/Memento.Core/MiddlewareHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected virtual Task OnInitializedAsync() {

public virtual RootState? HandleProviderDispatch(
RootState? state,
IStateChangedEventArgs<object,Command> e,
IStateChangedEventArgs<object, Command> e,
NextProviderMiddlewareCallback next
) => next(state, e);

Expand Down
2 changes: 0 additions & 2 deletions src/Memento.Core/StateChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Data;

namespace Memento.Core;

public enum StateChangeType {
Expand Down
17 changes: 14 additions & 3 deletions src/Memento.Core/StoreProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public RootState CaptureRootState() {
/// Captures a dictionary containing all stores keyed by their type name.
/// </summary>
/// <returns>A dictionary containing all stores keyed by their type name.</returns>
public Dictionary<string, IStore<object,Command>> CaptureStoreBag() {
public Dictionary<string, IStore<object, Command>> CaptureStoreBag() {
var map = new Dictionary<string, IStore<object, Command>>();
foreach (var item in ResolveAllStores()) {
map.Add(item.GetType().Name, item);
Expand All @@ -100,7 +100,7 @@ public async Task InitializeAsync() {
throw new InvalidOperationException("Already initialized.");
}

IsInitialized = true;

// observe all stores.
foreach (var store in ResolveAllStores()) {
var subscription = store.Subscribe(new StoreObserver<object, Command>(e => {
Expand All @@ -122,13 +122,22 @@ public async Task InitializeAsync() {
// Initialize all middleware.
foreach (var middleware in GetAllMiddleware()) {
try {
await middleware.InitializeAsync(_serviceContainer);
middleware.Initalize(_serviceContainer);
}
catch (Exception ex) {
throw new InvalidDataException($@"Failed to initialize memento middleware ""{ex.Message}""", ex);
}
}

foreach (var middleware in GetAllMiddleware()) {
try {
await middleware.InvokeInitializedAsync();
}
catch (Exception ex) {
throw new InvalidDataException($@"Failed to invoke OnInitialized memento middleware ""{ex.Message}""", ex);
}
}

// InitializeAsync all stores.
foreach (var store in ResolveAllStores()) {
try {
Expand All @@ -138,6 +147,8 @@ public async Task InitializeAsync() {
throw new InvalidDataException(@$"Failed to initialize memento provider ""{ex.Message}""", ex);
}
}
IsInitialized = true;
}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -15,6 +15,10 @@
</ItemGroup>


<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.JSInterop" Version="8.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.JSInterop" Version="7.*" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Fleck" Version="1.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="ScClient.Official" Version="1.2.1" />
</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion src/Memento.ReduxDevTool/ReduxDevToolMiddlewareHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Diagnostics;
using System.Text.Json;
using System.Text.RegularExpressions;
using static Memento.Core.Command;

namespace Memento.ReduxDevTool;

Expand Down
Loading

0 comments on commit f541735

Please sign in to comment.