-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
800 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using FreeRedis; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Volo.Abp.Localization; | ||
using Volo.Abp.Modularity; | ||
using Volo.Abp.VirtualFileSystem; | ||
|
||
namespace abpapi_net8 | ||
{ | ||
[DependsOn(typeof(AbpLocalizationModule))] | ||
public class ApiModule : AbpModule | ||
{ | ||
public override void ConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
// 将 RedisClient 注册为单例 | ||
RedisClient redisClient = new RedisClient("127.0.0.1:6379,defaultDatabase=13"); | ||
LanguageRedisOptions redisOptions = new LanguageRedisOptions | ||
{ | ||
KeyPrefix = "language", | ||
Capacity = 20, | ||
CheckExpired = TimeSpan.FromHours(1), | ||
CheckNewLanguageExpired = TimeSpan.FromMinutes(1), | ||
}; | ||
context.Services.AddSingleton<RedisClient>(redisClient); | ||
context.Services.AddSingleton<LanguageRedisOptions>(redisOptions); | ||
|
||
|
||
Configure<AbpVirtualFileSystemOptions>(options => | ||
{ | ||
options.FileSets.AddEmbedded<ApiModule>(); | ||
}); | ||
|
||
Configure<AbpLocalizationOptions>(options => | ||
{ | ||
options.Resources | ||
.Add<TestResource>("en") | ||
// 注入 Redis 多语言 | ||
.AddFreeRedis(redisClient, redisOptions) | ||
.AddVirtualJson("/Localization/Resources/Test"); | ||
}); | ||
} | ||
} | ||
} |
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,49 @@ | ||
using FreeRedis; | ||
using Microsoft.Extensions.Localization; | ||
using Volo.Abp; | ||
using Volo.Abp.Localization; | ||
|
||
namespace abpapi_net8 | ||
{ | ||
internal class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
RedisClient redisClient = new RedisClient("127.0.0.1:6379,defaultDatabase=13"); | ||
|
||
await redisClient.HMSetAsync("language:en", new Dictionary<string, string> | ||
{ | ||
{ "Hello", "Hello" }, | ||
{ "World", "World"}, | ||
}); | ||
await redisClient.HMSetAsync("language:zh-CN", new Dictionary<string, string> | ||
{ | ||
{ "Hello", "你好" }, | ||
{ "World", "世界" }, | ||
}); | ||
await redisClient.HMSetAsync("language:zh", new Dictionary<string, string> | ||
{ | ||
{ "Hello", "你好" }, | ||
{ "World", "世界" }, | ||
}); | ||
|
||
var provider = AbpApplicationFactory.Create<ApiModule>(); | ||
provider.Initialize(); | ||
var localizer = provider.ServiceProvider.GetRequiredService<IStringLocalizer<TestResource>>(); | ||
using (CultureHelper.Use("en")) | ||
{ | ||
if (localizer["Hello"].Value != "Hello") | ||
{ | ||
throw new Exception(); | ||
} | ||
} | ||
using (CultureHelper.Use("zh")) | ||
{ | ||
if (localizer["Hello"].Value != "你好") | ||
{ | ||
throw new Exception(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"profiles": { | ||
"abpapi_net8": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:51294;http://localhost:51295" | ||
} | ||
} | ||
} |
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,6 @@ | ||
namespace abpapi_net8 | ||
{ | ||
public class TestResource | ||
{ | ||
} | ||
} |
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Volo.Abp.Localization" Version="7.4.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\nuget\FreeRedis.Abp.Localization\FreeRedis.Abp.Localization.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,48 @@ | ||
using abpapi_net8; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Jobs; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Localization; | ||
using Volo.Abp; | ||
using Volo.Abp.Localization; | ||
|
||
namespace abpapi_net8_benchmark | ||
{ | ||
[SimpleJob(RuntimeMoniker.Net70)] | ||
[SimpleJob(RuntimeMoniker.Net80)] | ||
//[SimpleJob(RuntimeMoniker.NativeAot70)] | ||
// GC 分析 | ||
[MemoryDiagnoser] | ||
// 线程体积 | ||
[ThreadingDiagnoser] | ||
public partial class Ben | ||
{ | ||
private IStringLocalizer<TestResource> _stringLocalizer; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var application = AbpApplicationFactory.Create<ApiModule>(); | ||
|
||
application.Initialize(); | ||
|
||
_stringLocalizer = application.ServiceProvider.GetRequiredService<IStringLocalizer<TestResource>>(); | ||
|
||
var language = "zh"; | ||
using (CultureHelper.Use(language)) | ||
{ | ||
var value = _stringLocalizer["Hello"]; | ||
} | ||
} | ||
|
||
|
||
[Benchmark] | ||
public void GetValue() | ||
{ | ||
using (CultureHelper.Use("zh")) | ||
{ | ||
var value = _stringLocalizer["Hello"]; | ||
} | ||
} | ||
} | ||
} |
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,14 @@ | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace abpapi_net8_benchmark | ||
{ | ||
|
||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var summary = BenchmarkRunner.Run<Ben>(); | ||
Console.ReadLine(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/abpapi_net8_benchmark/Properties/PublishProfiles/FolderProfile.pubxml
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project> | ||
<PropertyGroup> | ||
<Configuration>Release</Configuration> | ||
<Platform>Any CPU</Platform> | ||
<PublishDir>bin\Release\net8.0\publish\</PublishDir> | ||
<PublishProtocol>FileSystem</PublishProtocol> | ||
<_TargetId>Folder</_TargetId> | ||
</PropertyGroup> | ||
</Project> |
20 changes: 20 additions & 0 deletions
20
examples/abpapi_net8_benchmark/abpapi_net8_benchmark.csproj
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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\abpapi_net8\ApiModule.cs" Link="ApiModule.cs" /> | ||
<Compile Include="..\abpapi_net8\TestResource.cs" Link="TestResource.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\nuget\FreeRedis.Abp.Localization\FreeRedis.Abp.Localization.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,80 @@ | ||
| ||
using Volo.Abp.AspNetCore.Mvc; | ||
using Volo.Abp.Modularity; | ||
using Volo.Abp; | ||
using FreeRedis; | ||
using Volo.Abp.Localization; | ||
using Volo.Abp.VirtualFileSystem; | ||
|
||
namespace abpapi_net8_server | ||
{ | ||
[DependsOn(typeof(AbpAspNetCoreMvcModule), typeof(AbpLocalizationModule))] | ||
public class AppModule : AbpModule | ||
{ | ||
public override void ConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
// 将 RedisClient 注册为单例 | ||
RedisClient redisClient = new RedisClient("127.0.0.1:6379,defaultDatabase=13"); | ||
|
||
redisClient.HMSet("language:en", new Dictionary<string, string> | ||
{ | ||
{ "Hello", "Hello" }, | ||
{ "World", "World"}, | ||
}); | ||
redisClient.HMSet("language:zh-CN", new Dictionary<string, string> | ||
{ | ||
{ "Hello", "你好" }, | ||
{ "World", "世界" }, | ||
}); | ||
redisClient.HMSet("language:zh", new Dictionary<string, string> | ||
{ | ||
{ "Hello", "你好" }, | ||
{ "World", "世界" }, | ||
}); | ||
|
||
LanguageRedisOptions redisOptions = new LanguageRedisOptions | ||
{ | ||
KeyPrefix = "language", | ||
Capacity = 20, | ||
CheckExpired = TimeSpan.FromHours(1), | ||
CheckNewLanguageExpired = TimeSpan.FromMinutes(1), | ||
}; | ||
context.Services.AddSingleton<RedisClient>(redisClient); | ||
context.Services.AddSingleton<LanguageRedisOptions>(redisOptions); | ||
|
||
Configure<AbpVirtualFileSystemOptions>(options => | ||
{ | ||
options.FileSets.AddEmbedded<AppModule>(); | ||
}); | ||
|
||
Configure<AbpLocalizationOptions>(options => | ||
{ | ||
options.Resources | ||
.Add<TestResource>("en") | ||
// 注入 Redis 多语言 | ||
.AddFreeRedis(redisClient, redisOptions); | ||
}); | ||
|
||
context.Services.AddSwaggerGen(); | ||
} | ||
public override void OnApplicationInitialization(ApplicationInitializationContext context) | ||
{ | ||
var app = context.GetApplicationBuilder(); | ||
var env = context.GetEnvironment(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseAuthorization(); | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseStaticFiles(); | ||
app.UseRouting(); | ||
app.UseConfiguredEndpoints(); | ||
} | ||
} | ||
} |
Oops, something went wrong.