Skip to content

feat: allow set configure concurrently #323

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

Merged
merged 2 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.6" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.6" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<PagedList<TView>> Handle(TQuery request, CancellationToken can
if (request.PagingParams.PageSize == 0 || totalCount == 0)
{
// need count only or no available item, short circuit here.
return new PagedList<TView>(Array.Empty<TView>(), request.PagingParams, totalCount);
return new PagedList<TView>([], request.PagingParams, totalCount);
}

ordered = ordered.Paging(request.PagingParams);
Expand Down Expand Up @@ -95,4 +95,4 @@ protected virtual IQueryable<TView> ProjectToView(TQuery query, IQueryable<TEnti
/// <param name="queryable">Projected <see cref="IQueryable{T}" />.</param>
/// <returns>The query result.</returns>
protected abstract Task<List<TView>> ToListAsync(TQuery query, IQueryable<TView> queryable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.15" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.6" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;

namespace Cnblogs.Architecture.Ddd.Infrastructure.Abstractions;
Expand All @@ -8,7 +9,7 @@ namespace Cnblogs.Architecture.Ddd.Infrastructure.Abstractions;
/// </summary>
public static class OrderBySegmentConfig
{
private static readonly Dictionary<Type, Dictionary<string, OrderBySegment>> Cache = new();
private static readonly ConcurrentDictionary<Type, ConcurrentDictionary<string, OrderBySegment>> Cache = new();

/// <summary>
/// 注册新的可排序列。
Expand All @@ -24,7 +25,7 @@ public static void RegisterSortableProperty<TSource, TProperty>(
var sourceType = typeof(TSource);
if (Cache.ContainsKey(sourceType) == false)
{
Cache[sourceType] = new Dictionary<string, OrderBySegment>(StringComparer.OrdinalIgnoreCase);
Cache[sourceType] = new ConcurrentDictionary<string, OrderBySegment>(StringComparer.OrdinalIgnoreCase);
}

Cache[sourceType][name] = new OrderBySegment(false, exp);
Expand Down Expand Up @@ -73,4 +74,24 @@ public static bool TryParseOrderBySegments<T>(

return segments.Count > 0;
}
}
}

/// <summary>
/// 管理可排序列的映射。
/// </summary>
/// <typeparam name="TEntity">The entity to config.</typeparam>
public static class OrderBySegmentConfig<TEntity>
{
/// <summary>
/// 注册新的可排序列。
/// </summary>
/// <param name="name">列名。</param>
/// <param name="exp">属性表达式。</param>
/// <typeparam name="TProperty">属性类型。</typeparam>
public static void RegisterSortableProperty<TProperty>(
string name,
Expression<Func<TEntity, TProperty>> exp)
{
OrderBySegmentConfig.RegisterSortableProperty(name, exp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1"/>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.6" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.4"/>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.6" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.8.31" />
<PackageReference Include="StackExchange.Redis" Version="2.8.41" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.6" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.6" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="aliyun.sdk.oss" Version="0.3.7" />
<PackageReference Include="aliyun.sdk.oss" Version="0.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Cnblogs.Serilog.Extensions" Version="1.1.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Serilog.Sinks.InMemory" Version="0.15.0" />
<PackageReference Include="Serilog.Sinks.InMemory.Assertions" Version="0.15.0" />
<PackageReference Include="Serilog.Sinks.InMemory" Version="0.16.0" />
<PackageReference Include="Serilog.Sinks.InMemory.Assertions" Version="0.16.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.15"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.4"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.6" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down