From e36624bf32763279c7fa9f8f226a37a1f5b120dc Mon Sep 17 00:00:00 2001 From: qinyouzeng Date: Wed, 28 Jun 2023 16:44:45 +0800 Subject: [PATCH 1/6] fix: fix less or great by datetime query, update keyword query operate by and --- .../ServiceCollectionExtensions.cs | 2 +- .../Extenistions/IElasticClientExtenstion.cs | 26 ++++++++++++------- .../Extenistions/ServiceExtenistion.cs | 5 +++- .../_Imports.cs | 1 + 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/Contrib/Authentication/Identity/Masa.Contrib.Authentication.Identity/ServiceCollectionExtensions.cs b/src/Contrib/Authentication/Identity/Masa.Contrib.Authentication.Identity/ServiceCollectionExtensions.cs index 10b643829..ce1565044 100644 --- a/src/Contrib/Authentication/Identity/Masa.Contrib.Authentication.Identity/ServiceCollectionExtensions.cs +++ b/src/Contrib/Authentication/Identity/Masa.Contrib.Authentication.Identity/ServiceCollectionExtensions.cs @@ -50,7 +50,7 @@ public static IServiceCollection AddMasaIdentityModel( private static IServiceCollection AddMasaIdentityCore(IServiceCollection services) { services.AddHttpContextAccessor(); - services.TryAddSingleton(); + services.TryAddScoped(); return services; } } diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs index 9d5619586..545324573 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs @@ -28,6 +28,7 @@ await client.SearchAsync(s => searchDescriptorFunc(s.Index(indexName)). } catch (Exception ex) { + ServiceExtenistion.Logger.LogError(ex, "SearchAsync execute error"); throw new UserFriendlyException($"SearchAsync execute error {ex.Message}"); } } @@ -37,21 +38,19 @@ await client.SearchAsync(s => searchDescriptorFunc(s.Index(indexName)). public static async Task> GetMappingAsync(this ICaller caller, string indexName, CancellationToken token = default) { var path = $"/{indexName}/_mapping"; - var result = await caller.GetAsync(path, false, token); + var result = await caller.GetAsync(path, token); var json = (JsonElement)result!; - JsonElement mapping = default; - bool findMapping = false; foreach (var item in json.EnumerateObject()) { - if (!findMapping && item.Value.TryGetProperty("mappings", out mapping)) + JsonElement mapping; + if (item.Value.TryGetProperty("mappings", out mapping)) { - findMapping = true; - break; + var mappings = GetRepProperties(mapping, default!)!; + if (mappings != null && mappings.Any()) + return mappings; } } - if (findMapping) - return GetRepProperties(mapping, default!)!; throw new UserFriendlyException($"can't find mapping for index: {indexName}"); } @@ -197,7 +196,7 @@ private static SearchDescriptor AddCondition(this Sear } if (!string.IsNullOrEmpty(query.Keyword)) { - list.Add(queryContainer => queryContainer.QueryString(queryString => queryString.Query(query.Keyword))); + list.Add(queryContainer => queryContainer.QueryString(queryString => queryString.Query(query.Keyword).DefaultOperator(Operator.And))); } query.AppendConditions(); @@ -257,6 +256,7 @@ private static Func, QueryContainer> CompareCo { CreateFieldKeyword(query.Name, mapping, out var fieldName, out var keyword); var value = query.Value; + bool isDate = value is DateTime; switch (query.Type) { @@ -265,12 +265,20 @@ private static Func, QueryContainer> CompareCo case ConditionTypes.NotEqual: return (container) => !container.Match(f => f.Field(keyword).Query(value?.ToString())); case ConditionTypes.Great: + if (isDate) + return (container) => container.DateRange(f => f.Field(keyword).GreaterThan((DateTime)value)); return (container) => container.Range(f => f.Field(keyword).GreaterThan(Convert.ToDouble(value))); case ConditionTypes.Less: + if (isDate) + return (container) => container.DateRange(f => f.Field(keyword).LessThan((DateTime)value)); return (container) => container.Range(f => f.Field(keyword).LessThan(Convert.ToDouble(value))); case ConditionTypes.GreatEqual: + if (isDate) + return (container) => container.DateRange(f => f.Field(keyword).GreaterThanOrEquals((DateTime)value)); return (container) => container.Range(f => f.Field(keyword).GreaterThanOrEquals(Convert.ToDouble(value))); case ConditionTypes.LessEqual: + if (isDate) + return (container) => container.DateRange(f => f.Field(keyword).LessThanOrEquals((DateTime)value)); return (container) => container.Range(f => f.Field(keyword).LessThanOrEquals(Convert.ToDouble(value))); case ConditionTypes.In: return (container) => container.Terms(f => f.Field(keyword).Terms((IEnumerable)value)); diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs index 3a34b21de..d82cd5639 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs @@ -7,6 +7,8 @@ namespace Microsoft.Extensions.DependencyInjection; public static class ServiceExtenistion { + internal static ILogger Logger { private set; get; } + public static IServiceCollection AddElasticClientLog(this IServiceCollection services, string[] nodes, string indexName) { ElasticConstant.InitLog(indexName, true); @@ -72,6 +74,7 @@ public static IServiceCollection AddElasticClientLogAndTrace(this IServiceCollec private static IServiceCollection AddElasticsearch(IServiceCollection services, string[] nodes, string name) { + Logger = services.BuildServiceProvider().GetRequiredService>(); return services.AddElasticsearch(name, options => { options.UseNodes(nodes).UseConnectionSettings(setting => setting.EnableApiVersioningHeader(false)); @@ -91,7 +94,7 @@ private static IServiceCollection AddElasticsearch(IServiceCollection services, Action callerAction, string name) { ArgumentNullException.ThrowIfNull(callerAction); - + Logger = services.BuildServiceProvider().GetRequiredService>(); return services.AddElasticsearch(name, elasticsearchConnectionAction) .AddCaller(name, option => option.UseHttpClient(callerAction).UseAuthentication()); } diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/_Imports.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/_Imports.cs index 07579054b..3ec947c7f 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/_Imports.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/_Imports.cs @@ -15,6 +15,7 @@ global using Masa.Utils.Data.Elasticsearch; global using Masa.Utils.Models; global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Extensions.Logging; global using Nest; global using System.Runtime.CompilerServices; global using System.Text.Json; From 0e32582ecced15fa2bf9b5f2e9403a28dab0ece8 Mon Sep 17 00:00:00 2001 From: qinyouzeng Date: Wed, 28 Jun 2023 18:00:21 +0800 Subject: [PATCH 2/6] chore: remove 8.0 --- ....Contrib.Caching.Distributed.StackExchangeRedis.Tests.csproj | 2 +- .../Masa.Utils.Extensions.DotNet.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests.csproj b/src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests.csproj index 3f757532e..76e911169 100644 --- a/src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests.csproj +++ b/src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0; + net6.0;net7.0; enable false enable diff --git a/src/Utils/Extensions/Tests/Masa.Utils.Extensions.DotNet.Tests/Masa.Utils.Extensions.DotNet.Tests.csproj b/src/Utils/Extensions/Tests/Masa.Utils.Extensions.DotNet.Tests/Masa.Utils.Extensions.DotNet.Tests.csproj index d24c99172..05c595b64 100644 --- a/src/Utils/Extensions/Tests/Masa.Utils.Extensions.DotNet.Tests/Masa.Utils.Extensions.DotNet.Tests.csproj +++ b/src/Utils/Extensions/Tests/Masa.Utils.Extensions.DotNet.Tests/Masa.Utils.Extensions.DotNet.Tests.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0; + net6.0;net7.0; enable enable false From 5f66f14d1ea1b8751aed88019946d64111932aba Mon Sep 17 00:00:00 2001 From: qinyouzeng Date: Wed, 28 Jun 2023 19:07:39 +0800 Subject: [PATCH 3/6] chore: update --- .../Extenistions/ServiceExtenistion.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs index d82cd5639..f9a97a25d 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs @@ -74,7 +74,7 @@ public static IServiceCollection AddElasticClientLogAndTrace(this IServiceCollec private static IServiceCollection AddElasticsearch(IServiceCollection services, string[] nodes, string name) { - Logger = services.BuildServiceProvider().GetRequiredService>(); + Logger = services.BuildServiceProvider().GetRequiredService>(); return services.AddElasticsearch(name, options => { options.UseNodes(nodes).UseConnectionSettings(setting => setting.EnableApiVersioningHeader(false)); @@ -94,7 +94,7 @@ private static IServiceCollection AddElasticsearch(IServiceCollection services, Action callerAction, string name) { ArgumentNullException.ThrowIfNull(callerAction); - Logger = services.BuildServiceProvider().GetRequiredService>(); + Logger = services.BuildServiceProvider().GetRequiredService>(); return services.AddElasticsearch(name, elasticsearchConnectionAction) .AddCaller(name, option => option.UseHttpClient(callerAction).UseAuthentication()); } From 0c2edbc8717a1e235be8876ff1821495f58720f6 Mon Sep 17 00:00:00 2001 From: qinyouzeng Date: Wed, 28 Jun 2023 19:51:07 +0800 Subject: [PATCH 4/6] chore: remove log --- .../Extenistions/IElasticClientExtenstion.cs | 3 +-- .../Extenistions/ServiceExtenistion.cs | 5 +---- .../Masa.Contrib.StackSdks.Tsc.Elasticsearch/_Imports.cs | 1 - 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs index 545324573..87bf59e9c 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs @@ -28,8 +28,7 @@ await client.SearchAsync(s => searchDescriptorFunc(s.Index(indexName)). } catch (Exception ex) { - ServiceExtenistion.Logger.LogError(ex, "SearchAsync execute error"); - throw new UserFriendlyException($"SearchAsync execute error {ex.Message}"); + throw new UserFriendlyException($"SearchAsync execute error", ex); } } diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs index f9a97a25d..3a34b21de 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs @@ -7,8 +7,6 @@ namespace Microsoft.Extensions.DependencyInjection; public static class ServiceExtenistion { - internal static ILogger Logger { private set; get; } - public static IServiceCollection AddElasticClientLog(this IServiceCollection services, string[] nodes, string indexName) { ElasticConstant.InitLog(indexName, true); @@ -74,7 +72,6 @@ public static IServiceCollection AddElasticClientLogAndTrace(this IServiceCollec private static IServiceCollection AddElasticsearch(IServiceCollection services, string[] nodes, string name) { - Logger = services.BuildServiceProvider().GetRequiredService>(); return services.AddElasticsearch(name, options => { options.UseNodes(nodes).UseConnectionSettings(setting => setting.EnableApiVersioningHeader(false)); @@ -94,7 +91,7 @@ private static IServiceCollection AddElasticsearch(IServiceCollection services, Action callerAction, string name) { ArgumentNullException.ThrowIfNull(callerAction); - Logger = services.BuildServiceProvider().GetRequiredService>(); + return services.AddElasticsearch(name, elasticsearchConnectionAction) .AddCaller(name, option => option.UseHttpClient(callerAction).UseAuthentication()); } diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/_Imports.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/_Imports.cs index 3ec947c7f..07579054b 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/_Imports.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/_Imports.cs @@ -15,7 +15,6 @@ global using Masa.Utils.Data.Elasticsearch; global using Masa.Utils.Models; global using Microsoft.Extensions.DependencyInjection; -global using Microsoft.Extensions.Logging; global using Nest; global using System.Runtime.CompilerServices; global using System.Text.Json; From aa0ee9d5f1469b727358b0783fcc1b83f631bfd3 Mon Sep 17 00:00:00 2001 From: qinyouzeng Date: Thu, 29 Jun 2023 11:14:16 +0800 Subject: [PATCH 5/6] fix: allow update change log and trace index name --- .../Constants/ElasticConstant.cs | 6 +-- .../Extenistions/ServiceExtenistion.cs | 38 ++++++++++++------- .../Service/LogServiceTests.cs | 5 +++ .../StaticConfig.cs | 1 + 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Constants/ElasticConstant.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Constants/ElasticConstant.cs index 082049c1e..4d8bf89bf 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Constants/ElasticConstant.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Constants/ElasticConstant.cs @@ -26,15 +26,15 @@ public static class ElasticConstant internal static void InitLog(string indexName, bool isIndependent = false) { - if (Log != null || string.IsNullOrEmpty(indexName)) + if (string.IsNullOrEmpty(indexName)) return; Log = new LogTraceSetting(indexName, isIndependent, TIMESTAMP); } internal static void InitTrace(string indexName, bool isIndependent = false) { - if (Trace != null || string.IsNullOrEmpty(indexName)) - return; + if (string.IsNullOrEmpty(indexName)) + return; Trace = new LogTraceSetting(indexName, isIndependent, TIMESTAMP); } } diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs index 3a34b21de..e95ad673e 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/ServiceExtenistion.cs @@ -10,7 +10,8 @@ public static class ServiceExtenistion public static IServiceCollection AddElasticClientLog(this IServiceCollection services, string[] nodes, string indexName) { ElasticConstant.InitLog(indexName, true); - AddElasticsearch(services, nodes, ElasticConstant.LOG_CALLER_CLIENT_NAME).AddSingleton(); + if (services.BuildServiceProvider().GetService() == null) + AddElasticsearch(services, nodes, ElasticConstant.LOG_CALLER_CLIENT_NAME).AddScoped(); ElasticConstant.Log.Mappings = GetLazyMapping(services, ElasticConstant.LOG_CALLER_CLIENT_NAME, indexName); return services; } @@ -19,8 +20,9 @@ public static IServiceCollection AddElasticClientLog(this IServiceCollection ser Action elasearchConnectionAction, Action callerAction, string indexName) { ElasticConstant.InitLog(indexName, true); - AddElasticsearch(services, elasearchConnectionAction, callerAction, ElasticConstant.LOG_CALLER_CLIENT_NAME) - .AddSingleton(); + if (services.BuildServiceProvider().GetService() == null) + AddElasticsearch(services, elasearchConnectionAction, callerAction, ElasticConstant.LOG_CALLER_CLIENT_NAME) + .AddScoped(); ElasticConstant.Log.Mappings = GetLazyMapping(services, ElasticConstant.LOG_CALLER_CLIENT_NAME, indexName); return services; } @@ -28,7 +30,8 @@ public static IServiceCollection AddElasticClientLog(this IServiceCollection ser public static IServiceCollection AddElasticClientTrace(this IServiceCollection services, string[] nodes, string indexName) { ElasticConstant.InitTrace(indexName, true); - AddElasticsearch(services, nodes, ElasticConstant.TRACE_CALLER_CLIENT_NAME).AddSingleton(); + if (services.BuildServiceProvider().GetService() == null) + AddElasticsearch(services, nodes, ElasticConstant.TRACE_CALLER_CLIENT_NAME).AddScoped(); ElasticConstant.Trace.Mappings = GetLazyMapping(services, ElasticConstant.TRACE_CALLER_CLIENT_NAME, indexName); return services; } @@ -37,8 +40,9 @@ public static IServiceCollection AddElasticClientTrace(this IServiceCollection s Action elasearchConnectionAction, Action callerAction, string indexName) { ElasticConstant.InitTrace(indexName, true); - AddElasticsearch(services, elasearchConnectionAction, callerAction, ElasticConstant.TRACE_CALLER_CLIENT_NAME) - .AddSingleton(); + if (services.BuildServiceProvider().GetService() == null) + AddElasticsearch(services, elasearchConnectionAction, callerAction, ElasticConstant.TRACE_CALLER_CLIENT_NAME) + .AddScoped(); ElasticConstant.Trace.Mappings = GetLazyMapping(services, ElasticConstant.TRACE_CALLER_CLIENT_NAME, indexName); return services; } @@ -48,9 +52,10 @@ public static IServiceCollection AddElasticClientLogAndTrace(this IServiceCollec { ElasticConstant.InitLog(logIndexName); ElasticConstant.InitTrace(traceIndexName); - AddElasticsearch(services, nodes, ElasticConstant.DEFAULT_CALLER_CLIENT_NAME) - .AddSingleton() - .AddSingleton(); + if (services.BuildServiceProvider().GetService() == null || services.BuildServiceProvider().GetService() == null) + AddElasticsearch(services, nodes, ElasticConstant.DEFAULT_CALLER_CLIENT_NAME) + .AddScoped() + .AddScoped(); ElasticConstant.Log.Mappings = GetLazyMapping(services, ElasticConstant.DEFAULT_CALLER_CLIENT_NAME, logIndexName); ElasticConstant.Trace.Mappings = GetLazyMapping(services, ElasticConstant.DEFAULT_CALLER_CLIENT_NAME, traceIndexName); return services; @@ -62,9 +67,10 @@ public static IServiceCollection AddElasticClientLogAndTrace(this IServiceCollec { ElasticConstant.InitLog(logIndexName); ElasticConstant.InitTrace(traceIndexName); - AddElasticsearch(services, elasearchConnectionAction, callerAction, ElasticConstant.DEFAULT_CALLER_CLIENT_NAME) - .AddSingleton() - .AddSingleton(); + if (services.BuildServiceProvider().GetService() == null || services.BuildServiceProvider().GetService() == null) + AddElasticsearch(services, elasearchConnectionAction, callerAction, ElasticConstant.DEFAULT_CALLER_CLIENT_NAME) + .AddScoped() + .AddScoped(); ElasticConstant.Log.Mappings = GetLazyMapping(services, ElasticConstant.DEFAULT_CALLER_CLIENT_NAME, logIndexName); ElasticConstant.Trace.Mappings = GetLazyMapping(services, ElasticConstant.DEFAULT_CALLER_CLIENT_NAME, traceIndexName); return services; @@ -91,9 +97,13 @@ private static IServiceCollection AddElasticsearch(IServiceCollection services, Action callerAction, string name) { ArgumentNullException.ThrowIfNull(callerAction); + var factory = services.BuildServiceProvider().GetService(); + var callerFactory = services.BuildServiceProvider().GetService(); - return services.AddElasticsearch(name, elasticsearchConnectionAction) - .AddCaller(name, option => option.UseHttpClient(callerAction).UseAuthentication()); + if (factory == null || factory.Create(name) == null || callerFactory == null || callerFactory.Create(name) == null) + services.AddElasticsearch(name, elasticsearchConnectionAction) + .AddCaller(name, option => option.UseHttpClient(callerAction).UseAuthentication()); + return services; } internal static IElasticClient CreateElasticClient(this IElasticClientFactory elasticsearchFactory, bool isLog) diff --git a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Elasticsearch.Tests/Service/LogServiceTests.cs b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Elasticsearch.Tests/Service/LogServiceTests.cs index e4d991eb4..9f90aa5e5 100644 --- a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Elasticsearch.Tests/Service/LogServiceTests.cs +++ b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Elasticsearch.Tests/Service/LogServiceTests.cs @@ -17,6 +17,10 @@ public static void InitializeLog(TestContext testContext) httpClient.Send(StaticConfig.CreateMessage(StaticConfig.LOG_INDEX_NAME, HttpMethod.Delete)); httpClient.Send(StaticConfig.CreateMessage(StaticConfig.LOG_INDEX_NAME, HttpMethod.Put, mapping)); httpClient.Send(StaticConfig.CreateMessage($"{StaticConfig.LOG_INDEX_NAME}/_doc", HttpMethod.Post, dataJson)); + + httpClient.Send(StaticConfig.CreateMessage(StaticConfig.LOG_INDEX_RENAME, HttpMethod.Delete)); + httpClient.Send(StaticConfig.CreateMessage(StaticConfig.LOG_INDEX_RENAME, HttpMethod.Put, mapping)); + httpClient.Send(StaticConfig.CreateMessage($"{StaticConfig.LOG_INDEX_RENAME}/_doc", HttpMethod.Post, dataJson)); Task.Delay(1000).Wait(); } @@ -25,6 +29,7 @@ public void Initialize() { ServiceCollection services = new(); services.AddElasticClientLog(new string[] { StaticConfig.HOST }, StaticConfig.LOG_INDEX_NAME); + services.AddElasticClientLog(new string[] { StaticConfig.HOST }, StaticConfig.LOG_INDEX_RENAME); var serviceProvider = services.BuildServiceProvider(); _logService = serviceProvider.GetRequiredService(); } diff --git a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Elasticsearch.Tests/StaticConfig.cs b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Elasticsearch.Tests/StaticConfig.cs index ac23b2ad6..18b3d1adf 100644 --- a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Elasticsearch.Tests/StaticConfig.cs +++ b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Elasticsearch.Tests/StaticConfig.cs @@ -6,6 +6,7 @@ namespace Masa.Contrib.StackSdks.Tsc.Elasticsearch.Tests; public static class StaticConfig { internal const string LOG_INDEX_NAME = "test_logs"; + internal const string LOG_INDEX_RENAME = "test_logs_new"; internal const string HOST = "http://localhost:9200"; internal const string TRACE_INDEX_NAME = "test_traces"; private static IConfiguration Configuration; From faec1f4f8de9792cc36cf1088e4fa507712878e0 Mon Sep 17 00:00:00 2001 From: qinyouzeng Date: Thu, 29 Jun 2023 18:00:54 +0800 Subject: [PATCH 6/6] chore: restore --- .../ServiceCollectionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Contrib/Authentication/Identity/Masa.Contrib.Authentication.Identity/ServiceCollectionExtensions.cs b/src/Contrib/Authentication/Identity/Masa.Contrib.Authentication.Identity/ServiceCollectionExtensions.cs index ce1565044..10b643829 100644 --- a/src/Contrib/Authentication/Identity/Masa.Contrib.Authentication.Identity/ServiceCollectionExtensions.cs +++ b/src/Contrib/Authentication/Identity/Masa.Contrib.Authentication.Identity/ServiceCollectionExtensions.cs @@ -50,7 +50,7 @@ public static IServiceCollection AddMasaIdentityModel( private static IServiceCollection AddMasaIdentityCore(IServiceCollection services) { services.AddHttpContextAccessor(); - services.TryAddScoped(); + services.TryAddSingleton(); return services; } }