|
|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|