diff --git a/Sln.Wcs.Cache/Sln.Wcs.Cache.csproj b/Sln.Wcs.Cache/Sln.Wcs.Cache.csproj new file mode 100644 index 0000000..725b311 --- /dev/null +++ b/Sln.Wcs.Cache/Sln.Wcs.Cache.csproj @@ -0,0 +1,19 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + diff --git a/Sln.Wcs.sln b/Sln.Wcs.sln index f28fc54..ff73ae9 100644 --- a/Sln.Wcs.sln +++ b/Sln.Wcs.sln @@ -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 diff --git a/Sln.Wcs/Program.cs b/Sln.Wcs/Program.cs index ed29ed0..0240093 100644 --- a/Sln.Wcs/Program.cs +++ b/Sln.Wcs/Program.cs @@ -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"] + })); + } + + /// + /// Apollo 配置中心 + /// + /// + /// + /// + 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(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(); } } diff --git a/Sln.Wcs/Sln.Wcs.csproj b/Sln.Wcs/Sln.Wcs.csproj index f3da775..930eee3 100644 --- a/Sln.Wcs/Sln.Wcs.csproj +++ b/Sln.Wcs/Sln.Wcs.csproj @@ -26,6 +26,7 @@ +