add - 添加cache缓存模块

master
wenjy 1 month ago
parent 8b3603d0ec
commit 3555b499b0

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NeoSmart.Caching.Sqlite" Version="9.0.1" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.4.0" />
<PackageReference Include="ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Sln.Wcs.Repository\Sln.Wcs.Repository.csproj" />
<ProjectReference Include="..\Sln.Wcs.Serilog\Sln.Wcs.Serilog.csproj" />
</ItemGroup>
</Project>

@ -20,6 +20,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sln.Wcs.Serilog", "Sln.Wcs.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Wcs.Repository", "Sln.Wcs.Repository\Sln.Wcs.Repository.csproj", "{549AF273-88BE-4316-88F8-CAD82BC5F1E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sln.Wcs.Cache", "Sln.Wcs.Cache\Sln.Wcs.Cache.csproj", "{97940311-1DE9-4282-8EE0-0174513BF245}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -62,6 +64,10 @@ Global
{549AF273-88BE-4316-88F8-CAD82BC5F1E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{549AF273-88BE-4316-88F8-CAD82BC5F1E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{549AF273-88BE-4316-88F8-CAD82BC5F1E7}.Release|Any CPU.Build.0 = Release|Any CPU
{97940311-1DE9-4282-8EE0-0174513BF245}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97940311-1DE9-4282-8EE0-0174513BF245}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97940311-1DE9-4282-8EE0-0174513BF245}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97940311-1DE9-4282-8EE0-0174513BF245}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -2,11 +2,14 @@ using System.Reflection;
using Com.Ctrip.Framework.Apollo;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NeoSmart.Caching.Sqlite;
using Newtonsoft.Json;
using Sln.Wcs.HikRoBotSdk;
using Sln.Wcs.Model.Configs;
using Sln.Wcs.Repository;
using Sln.Wcs.Serilog;
using ZiggyCreatures.Caching.Fusion;
using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson;
namespace Sln.Wcs
{
@ -32,9 +35,48 @@ namespace Sln.Wcs
private static void ConfigureServices(IServiceCollection services)
{
#region Apollo配置
var basePath = AppContext.BaseDirectory;
ApolloConfigureServices(services,ref basePath,out IConfiguration apolloConfiguration);
Assembly[] assemblies = {
Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Common.dll")),
Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Cache.dll")),
Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Repository.dll")),
Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HikRoBotApi.dll")),
Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HikRoBotSdk.dll")),
};
services.Scan(scan => scan.FromAssemblies(assemblies)
.AddClasses()
.AsImplementedInterfaces()
.AsSelf()
.WithTransientLifetime());
services.AddSingleton(typeof(SerilogHelper));
services.AddSqlSugarSetup();
services.AddFusionCache()
.WithSerializer(
new FusionCacheNewtonsoftJsonSerializer()
)
.WithDistributedCache(new SqliteCache(new SqliteCacheOptions
{
CachePath = apolloConfiguration["cachePath"]
}));
}
/// <summary>
/// Apollo 配置中心
/// </summary>
/// <param name="services"></param>
/// <param name="basePath"></param>
/// <param name="apolloConfiguration"></param>
private static void ApolloConfigureServices(IServiceCollection services, ref string basePath, out IConfiguration apolloConfiguration)
{
var localConfiguration = new ConfigurationBuilder()
.SetBasePath(basePath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
@ -50,28 +92,10 @@ namespace Sln.Wcs
.AddApollo(apolloConfigSection)
.AddDefault();
var apolloConfiguration = configurationBuilder.Build();
apolloConfiguration = configurationBuilder.Build();
services.Remove(new ServiceDescriptor(typeof(IConfiguration), localConfiguration));
services.AddSingleton<IConfiguration>(apolloConfiguration);
#endregion
Assembly[] assemblies = {
Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Common.dll")),
Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.Repository.dll")),
Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HikRoBotApi.dll")),
Assembly.LoadFrom(Path.Combine(basePath, "Sln.Wcs.HikRoBotSdk.dll")),
};
services.Scan(scan => scan.FromAssemblies(assemblies)
.AddClasses()
.AsImplementedInterfaces()
.AsSelf()
.WithTransientLifetime());
services.AddSingleton(typeof(SerilogHelper));
services.AddSqlSugarSetup();
}
}

@ -26,6 +26,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Sln.Wcs.Cache\Sln.Wcs.Cache.csproj" />
<ProjectReference Include="..\Sln.Wcs.HikRoBotApi\Sln.Wcs.HikRoBotApi.csproj" />
<ProjectReference Include="..\Sln.Wcs.HikRoBotSdk\Sln.Wcs.HikRoBotSdk.csproj" />
<ProjectReference Include="..\Sln.Wcs.Repository\Sln.Wcs.Repository.csproj" />

Loading…
Cancel
Save