From f3088ef8db4728bc24777f71723980d36c034472 Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Fri, 5 Aug 2022 14:10:38 +0800 Subject: [PATCH 1/7] feat: Add AppConfig --- .../Masa.BuildingBlocks.Data.UoW/_Imports.cs | 1 - .../MasaDbContextConfigurationOptions.cs | 2 +- .../Data/Masa.BuildingBlocks.Data/_Imports.cs | 1 - .../Masa.Contrib.Data.EFCore/_Imports.cs | 1 - .../Masa.Contrib.Data.UoW.EFCore/_Imports.cs | 1 - .../_Imports.cs | 1 - .../_Imports.cs | 1 - .../_Imports.cs | 1 - .../Masa.Contrib.Isolation/_Imports.cs | 1 - .../UnitOfWorkAccessor.cs | 2 -- .../Masa.Contrib.Isolation.Tests/_Imports.cs | 1 - ...a.Utils.Development.Dapr.AspNetCore.csproj | 1 + .../ServiceCollectionExtensions.cs | 19 ++++++++++++++++--- .../_Imports.cs | 1 + .../Masa.Utils.Models.Config/AppConfig.cs | 13 ++++++++++--- .../Extensions/AppConfigExtensions.cs | 12 ++++++++++++ .../Masa.Utils.Models.Config/_Imports.cs | 4 ++++ .../TestDispatcher.cs | 8 -------- .../_Imports.cs | 3 +++ 19 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 src/Utils/Models/Masa.Utils.Models.Config/Extensions/AppConfigExtensions.cs create mode 100644 src/Utils/Models/Masa.Utils.Models.Config/_Imports.cs diff --git a/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data.UoW/_Imports.cs b/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data.UoW/_Imports.cs index a376a67ba..48c1b6586 100644 --- a/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data.UoW/_Imports.cs +++ b/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data.UoW/_Imports.cs @@ -1,6 +1,5 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -global using Masa.BuildingBlocks.Data.Options; global using System.Data.Common; global using System.Text.Json.Serialization; diff --git a/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/Options/MasaDbContextConfigurationOptions.cs b/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/Options/MasaDbContextConfigurationOptions.cs index 3e32d3e29..235b28884 100644 --- a/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/Options/MasaDbContextConfigurationOptions.cs +++ b/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/Options/MasaDbContextConfigurationOptions.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.BuildingBlocks.Data.Options; +namespace Masa.BuildingBlocks.Data; public class MasaDbContextConfigurationOptions { diff --git a/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/_Imports.cs b/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/_Imports.cs index 5096951d3..da9630c2d 100644 --- a/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/_Imports.cs +++ b/src/BuildingBlocks/Data/Masa.BuildingBlocks.Data/_Imports.cs @@ -1,5 +1,4 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -global using Masa.BuildingBlocks.Data.Options; global using System.Reflection; diff --git a/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore/_Imports.cs b/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore/_Imports.cs index c74483086..252713510 100644 --- a/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore/_Imports.cs +++ b/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore/_Imports.cs @@ -5,7 +5,6 @@ global using Masa.BuildingBlocks.Configuration; global using Masa.BuildingBlocks.Data; global using Masa.BuildingBlocks.Data.Contracts.DataFiltering; -global using Masa.BuildingBlocks.Data.Options; global using Masa.BuildingBlocks.Ddd.Domain.Entities; global using Masa.BuildingBlocks.Ddd.Domain.Entities.Auditing; global using Masa.BuildingBlocks.Ddd.Domain.Events; diff --git a/src/Contrib/Data/UoW/Masa.Contrib.Data.UoW.EFCore/_Imports.cs b/src/Contrib/Data/UoW/Masa.Contrib.Data.UoW.EFCore/_Imports.cs index 47cc95067..1e544fdb9 100644 --- a/src/Contrib/Data/UoW/Masa.Contrib.Data.UoW.EFCore/_Imports.cs +++ b/src/Contrib/Data/UoW/Masa.Contrib.Data.UoW.EFCore/_Imports.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. See LICENSE.txt in the project root for license information. global using Masa.BuildingBlocks.Data; -global using Masa.BuildingBlocks.Data.Options; global using Masa.BuildingBlocks.Data.UoW; global using Masa.BuildingBlocks.Ddd.Domain.Events; global using Masa.BuildingBlocks.Dispatcher.Events; diff --git a/src/Contrib/Data/UoW/Tests/Masa.Contrib.Data.UoW.EFCore.Tests/_Imports.cs b/src/Contrib/Data/UoW/Tests/Masa.Contrib.Data.UoW.EFCore.Tests/_Imports.cs index 33b87445a..6d430c79b 100644 --- a/src/Contrib/Data/UoW/Tests/Masa.Contrib.Data.UoW.EFCore.Tests/_Imports.cs +++ b/src/Contrib/Data/UoW/Tests/Masa.Contrib.Data.UoW.EFCore.Tests/_Imports.cs @@ -3,7 +3,6 @@ global using Masa.BuildingBlocks.Configuration; global using Masa.BuildingBlocks.Data; -global using Masa.BuildingBlocks.Data.Options; global using Masa.BuildingBlocks.Data.UoW; global using Masa.BuildingBlocks.Dispatcher.Events; global using Masa.Contrib.Data.EFCore; diff --git a/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests/_Imports.cs b/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests/_Imports.cs index 30d002d09..2b42073f5 100644 --- a/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests/_Imports.cs +++ b/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests/_Imports.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. See LICENSE.txt in the project root for license information. global using Masa.BuildingBlocks.Data; -global using Masa.BuildingBlocks.Data.Options; global using Masa.BuildingBlocks.Data.UoW; global using Masa.BuildingBlocks.Dispatcher.Events; global using Masa.BuildingBlocks.Dispatcher.IntegrationEvents; diff --git a/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Tests/_Imports.cs b/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Tests/_Imports.cs index 9dc39e12a..2f24d8931 100644 --- a/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Tests/_Imports.cs +++ b/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Tests/_Imports.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. See LICENSE.txt in the project root for license information. global using Masa.BuildingBlocks.Data; -global using Masa.BuildingBlocks.Data.Options; global using Masa.BuildingBlocks.Data.UoW; global using Masa.BuildingBlocks.Dispatcher.Events; global using Masa.BuildingBlocks.Dispatcher.IntegrationEvents; diff --git a/src/Contrib/Isolation/Masa.Contrib.Isolation/_Imports.cs b/src/Contrib/Isolation/Masa.Contrib.Isolation/_Imports.cs index 85a7c4dad..72e2dfe5e 100644 --- a/src/Contrib/Isolation/Masa.Contrib.Isolation/_Imports.cs +++ b/src/Contrib/Isolation/Masa.Contrib.Isolation/_Imports.cs @@ -3,7 +3,6 @@ global using Masa.BuildingBlocks.Configuration; global using Masa.BuildingBlocks.Data; -global using Masa.BuildingBlocks.Data.Options; global using Masa.BuildingBlocks.Data.UoW; global using Masa.BuildingBlocks.Dispatcher.Events; global using Masa.BuildingBlocks.Isolation; diff --git a/src/Contrib/Isolation/Tests/Masa.Contrib.Isolation.Tests/UnitOfWorkAccessor.cs b/src/Contrib/Isolation/Tests/Masa.Contrib.Isolation.Tests/UnitOfWorkAccessor.cs index 2b9d6c1d2..e16da621f 100644 --- a/src/Contrib/Isolation/Tests/Masa.Contrib.Isolation.Tests/UnitOfWorkAccessor.cs +++ b/src/Contrib/Isolation/Tests/Masa.Contrib.Isolation.Tests/UnitOfWorkAccessor.cs @@ -1,8 +1,6 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -using Masa.BuildingBlocks.Data.Options; - namespace Masa.Contrib.Isolation.Tests; public class UnitOfWorkAccessor: IUnitOfWorkAccessor diff --git a/src/Contrib/Isolation/Tests/Masa.Contrib.Isolation.Tests/_Imports.cs b/src/Contrib/Isolation/Tests/Masa.Contrib.Isolation.Tests/_Imports.cs index 8dc426a07..c4c554745 100644 --- a/src/Contrib/Isolation/Tests/Masa.Contrib.Isolation.Tests/_Imports.cs +++ b/src/Contrib/Isolation/Tests/Masa.Contrib.Isolation.Tests/_Imports.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. See LICENSE.txt in the project root for license information. global using Masa.BuildingBlocks.Data; -global using Masa.BuildingBlocks.Data.Options; global using Masa.BuildingBlocks.Data.UoW; global using Masa.BuildingBlocks.Dispatcher.Events; global using Masa.BuildingBlocks.Isolation.Environment; diff --git a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/Masa.Utils.Development.Dapr.AspNetCore.csproj b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/Masa.Utils.Development.Dapr.AspNetCore.csproj index 5774c7add..09549d99b 100644 --- a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/Masa.Utils.Development.Dapr.AspNetCore.csproj +++ b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/Masa.Utils.Development.Dapr.AspNetCore.csproj @@ -9,6 +9,7 @@ + diff --git a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/ServiceCollectionExtensions.cs b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/ServiceCollectionExtensions.cs index 8c8cb20dc..6cc254d46 100644 --- a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/ServiceCollectionExtensions.cs +++ b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/ServiceCollectionExtensions.cs @@ -43,19 +43,32 @@ private static IServiceCollection AddDaprStarter(this IServiceCollection service services.AddSingleton(); action.Invoke(); - if (isDelay) - return services.AddHostedService(); - var serviceProvider = services.BuildServiceProvider(); var options = serviceProvider.GetRequiredService>(); + string appId = string.Empty; + services.Configure(appConfig => + { + if (string.IsNullOrEmpty(appConfig.AppId) && !string.IsNullOrEmpty(appId)) + appConfig.AppId = appId; + }); + if (isDelay) + { + options.OnChange(daprOptions => + { + appId = daprOptions.GetAppId(); + }); + return services.AddHostedService(); + } ArgumentNullException.ThrowIfNull(options.CurrentValue.AppPort, nameof(options.CurrentValue.AppPort)); var daprProcess = serviceProvider.GetRequiredService(); options.OnChange(daprOptions => { + appId = daprOptions.GetAppId(); daprProcess.Refresh(daprOptions); }); daprProcess.Start(options.CurrentValue); + appId = options.CurrentValue.GetAppId(); CompleteDaprEnvironment(options.CurrentValue.DaprHttpPort, options.CurrentValue.DaprGrpcPort); return services; } diff --git a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/_Imports.cs b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/_Imports.cs index 5509a71e7..1b4534981 100644 --- a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/_Imports.cs +++ b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/_Imports.cs @@ -3,6 +3,7 @@ global using Masa.Utils.Development.Dapr; global using Masa.Utils.Development.Dapr.AspNetCore; +global using Masa.Utils.Models.Config; global using Microsoft.AspNetCore.Hosting.Server; global using Microsoft.AspNetCore.Hosting.Server.Features; global using Microsoft.Extensions.Configuration; diff --git a/src/Utils/Models/Masa.Utils.Models.Config/AppConfig.cs b/src/Utils/Models/Masa.Utils.Models.Config/AppConfig.cs index c5443c2eb..f62c44319 100644 --- a/src/Utils/Models/Masa.Utils.Models.Config/AppConfig.cs +++ b/src/Utils/Models/Masa.Utils.Models.Config/AppConfig.cs @@ -1,9 +1,16 @@ - -// Copyright (c) MASA Stack All rights reserved. +// Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. namespace Masa.Utils.Models.Config; + +/// +/// Apply global configuration +/// public class AppConfig { - public string AppId { get; set; } = string.Empty; + public string? AppId { get; set; } + + public string? Environment { get; set; } + + public string? Cluster { get; set; } } diff --git a/src/Utils/Models/Masa.Utils.Models.Config/Extensions/AppConfigExtensions.cs b/src/Utils/Models/Masa.Utils.Models.Config/Extensions/AppConfigExtensions.cs new file mode 100644 index 000000000..89389582a --- /dev/null +++ b/src/Utils/Models/Masa.Utils.Models.Config/Extensions/AppConfigExtensions.cs @@ -0,0 +1,12 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.Utils.Models.Config; + +public static class AppConfigExtensions +{ + public static string? GetAppId(this AppConfig config) + { + return config.AppId ??(Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName().Name; + } +} diff --git a/src/Utils/Models/Masa.Utils.Models.Config/_Imports.cs b/src/Utils/Models/Masa.Utils.Models.Config/_Imports.cs new file mode 100644 index 000000000..d2670a845 --- /dev/null +++ b/src/Utils/Models/Masa.Utils.Models.Config/_Imports.cs @@ -0,0 +1,4 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +global using System.Reflection; diff --git a/test/Masa.EventBus.IntegrationTests/TestDispatcher.cs b/test/Masa.EventBus.IntegrationTests/TestDispatcher.cs index de6ace755..72e4f1ca4 100644 --- a/test/Masa.EventBus.IntegrationTests/TestDispatcher.cs +++ b/test/Masa.EventBus.IntegrationTests/TestDispatcher.cs @@ -1,14 +1,6 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -using Masa.EventBus.IntegrationTests.Application.Command; -using Masa.EventBus.IntegrationTests.Application.Events; -using Masa.EventBus.IntegrationTests.Application.Queries; -using Masa.EventBus.IntegrationTests.Domain.Aggregate; -using Masa.EventBus.IntegrationTests.Infrastructure; -using Masa.EventBus.IntegrationTests.Infrastructure.Extensions; -using Masa.EventBus.IntegrationTests.Infrastructure.Middleware; - namespace Masa.EventBus.IntegrationTests; [TestClass] diff --git a/test/Masa.EventBus.IntegrationTests/_Imports.cs b/test/Masa.EventBus.IntegrationTests/_Imports.cs index 3cc1ea8d5..59cb9e21f 100644 --- a/test/Masa.EventBus.IntegrationTests/_Imports.cs +++ b/test/Masa.EventBus.IntegrationTests/_Imports.cs @@ -16,6 +16,9 @@ global using Masa.Contrib.Dispatcher.Events; global using Masa.Contrib.Dispatcher.IntegrationEvents; global using Masa.Contrib.Dispatcher.IntegrationEvents.EventLogs.EFCore; +global using Masa.EventBus.IntegrationTests.Application.Command; +global using Masa.EventBus.IntegrationTests.Application.Events; +global using Masa.EventBus.IntegrationTests.Application.Queries; global using Masa.EventBus.IntegrationTests.Domain.Aggregate; global using Masa.EventBus.IntegrationTests.Infrastructure; global using Masa.EventBus.IntegrationTests.Infrastructure.Extensions; From 954a264d92bb9194c3458ef08055e4649c7b32b1 Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Fri, 5 Aug 2022 16:38:21 +0800 Subject: [PATCH 2/7] refactor: refactor AppConfig --- ...a.Utils.Development.Dapr.AspNetCore.csproj | 17 +++++++++-------- .../ServiceCollectionExtensions.cs | 19 +++---------------- .../_Imports.cs | 1 - .../Masa.Utils.Models.Config/AppConfig.cs | 9 +-------- .../Extensions/AppConfigExtensions.cs | 12 ------------ 5 files changed, 13 insertions(+), 45 deletions(-) delete mode 100644 src/Utils/Models/Masa.Utils.Models.Config/Extensions/AppConfigExtensions.cs diff --git a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/Masa.Utils.Development.Dapr.AspNetCore.csproj b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/Masa.Utils.Development.Dapr.AspNetCore.csproj index 09549d99b..b057dbee0 100644 --- a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/Masa.Utils.Development.Dapr.AspNetCore.csproj +++ b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/Masa.Utils.Development.Dapr.AspNetCore.csproj @@ -1,15 +1,16 @@ - - net6.0 - enable - enable - + + net6.0 + enable + enable + - + + - - + + diff --git a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/ServiceCollectionExtensions.cs b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/ServiceCollectionExtensions.cs index 6cc254d46..8c8cb20dc 100644 --- a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/ServiceCollectionExtensions.cs +++ b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/ServiceCollectionExtensions.cs @@ -43,32 +43,19 @@ private static IServiceCollection AddDaprStarter(this IServiceCollection service services.AddSingleton(); action.Invoke(); - var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - string appId = string.Empty; - services.Configure(appConfig => - { - if (string.IsNullOrEmpty(appConfig.AppId) && !string.IsNullOrEmpty(appId)) - appConfig.AppId = appId; - }); if (isDelay) - { - options.OnChange(daprOptions => - { - appId = daprOptions.GetAppId(); - }); return services.AddHostedService(); - } + + var serviceProvider = services.BuildServiceProvider(); + var options = serviceProvider.GetRequiredService>(); ArgumentNullException.ThrowIfNull(options.CurrentValue.AppPort, nameof(options.CurrentValue.AppPort)); var daprProcess = serviceProvider.GetRequiredService(); options.OnChange(daprOptions => { - appId = daprOptions.GetAppId(); daprProcess.Refresh(daprOptions); }); daprProcess.Start(options.CurrentValue); - appId = options.CurrentValue.GetAppId(); CompleteDaprEnvironment(options.CurrentValue.DaprHttpPort, options.CurrentValue.DaprGrpcPort); return services; } diff --git a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/_Imports.cs b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/_Imports.cs index 1b4534981..5509a71e7 100644 --- a/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/_Imports.cs +++ b/src/Utils/Development/Dapr/Masa.Utils.Development.Dapr.AspNetCore/_Imports.cs @@ -3,7 +3,6 @@ global using Masa.Utils.Development.Dapr; global using Masa.Utils.Development.Dapr.AspNetCore; -global using Masa.Utils.Models.Config; global using Microsoft.AspNetCore.Hosting.Server; global using Microsoft.AspNetCore.Hosting.Server.Features; global using Microsoft.Extensions.Configuration; diff --git a/src/Utils/Models/Masa.Utils.Models.Config/AppConfig.cs b/src/Utils/Models/Masa.Utils.Models.Config/AppConfig.cs index f62c44319..1206141a7 100644 --- a/src/Utils/Models/Masa.Utils.Models.Config/AppConfig.cs +++ b/src/Utils/Models/Masa.Utils.Models.Config/AppConfig.cs @@ -3,14 +3,7 @@ namespace Masa.Utils.Models.Config; -/// -/// Apply global configuration -/// public class AppConfig { - public string? AppId { get; set; } - - public string? Environment { get; set; } - - public string? Cluster { get; set; } + public string AppId { get; set; } = string.Empty; } diff --git a/src/Utils/Models/Masa.Utils.Models.Config/Extensions/AppConfigExtensions.cs b/src/Utils/Models/Masa.Utils.Models.Config/Extensions/AppConfigExtensions.cs deleted file mode 100644 index 89389582a..000000000 --- a/src/Utils/Models/Masa.Utils.Models.Config/Extensions/AppConfigExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the MIT License. See LICENSE.txt in the project root for license information. - -namespace Masa.Utils.Models.Config; - -public static class AppConfigExtensions -{ - public static string? GetAppId(this AppConfig config) - { - return config.AppId ??(Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName().Name; - } -} From 95148eea7489dd7bf0e1c21dd36dcfc78168211d Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Fri, 5 Aug 2022 16:38:54 +0800 Subject: [PATCH 3/7] feat: Initialize Framework configuration --- .../Options/MasaAppConfigureOptions.cs | 15 ++++++++++++++ .../ConfigurationManagerExtensions.cs | 13 ++++++++++++ .../WebApplicationBuilderExtensions.cs | 20 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 src/BuildingBlocks/Configuration/Masa.BuildingBlocks.Configuration/Options/MasaAppConfigureOptions.cs create mode 100644 src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationManagerExtensions.cs diff --git a/src/BuildingBlocks/Configuration/Masa.BuildingBlocks.Configuration/Options/MasaAppConfigureOptions.cs b/src/BuildingBlocks/Configuration/Masa.BuildingBlocks.Configuration/Options/MasaAppConfigureOptions.cs new file mode 100644 index 000000000..c2b814864 --- /dev/null +++ b/src/BuildingBlocks/Configuration/Masa.BuildingBlocks.Configuration/Options/MasaAppConfigureOptions.cs @@ -0,0 +1,15 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.Configuration.Options; + +public class MasaAppConfigureOptions +{ + public string AppId { get; set; } + + public string Environment { get; set; } + + public string Cluster { get; set; } + + public Dictionary Data { get; set; } = new(); +} diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationManagerExtensions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationManagerExtensions.cs new file mode 100644 index 000000000..2ebeddb08 --- /dev/null +++ b/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationManagerExtensions.cs @@ -0,0 +1,13 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.Contrib.Configuration.Internal; + +internal static class ConfigurationManagerExtensions +{ + public static string GetConfigurationValue(this ConfigurationManager configurationManager, string key, Func func) + { + var configurationValue = configurationManager[key]; + return string.IsNullOrWhiteSpace(configurationValue) ? func() : configurationValue; + } +} diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/WebApplicationBuilderExtensions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/WebApplicationBuilderExtensions.cs index bb0a3beaf..4b2135d83 100644 --- a/src/Contrib/Configuration/Masa.Contrib.Configuration/WebApplicationBuilderExtensions.cs +++ b/src/Contrib/Configuration/Masa.Contrib.Configuration/WebApplicationBuilderExtensions.cs @@ -5,6 +5,26 @@ namespace Microsoft.AspNetCore.Builder; public static class WebApplicationBuilderExtensions { + public static WebApplicationBuilder InitializeAppConfiguration(this WebApplicationBuilder builder) + { + var configuration = builder.Configuration; + builder.Services.Configure(options => + { + if (string.IsNullOrWhiteSpace(options.AppId)) + options.AppId = configuration.GetConfigurationValue(nameof(MasaAppConfigureOptions.AppId), + () => (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName().Name!.Replace(".", "-")); + + if (string.IsNullOrWhiteSpace(options.Environment)) + options.Environment = configuration.GetConfigurationValue("ASPNETCORE_ENVIRONMENT", + () => "Production"); + + if (string.IsNullOrWhiteSpace(options.Cluster)) + options.Environment = configuration.GetConfigurationValue(nameof(MasaAppConfigureOptions.Cluster), + () => "Default"); + }); + return builder; + } + public static WebApplicationBuilder AddMasaConfiguration( this WebApplicationBuilder builder, Action? configureDelegate = null) From 26ae747341cd656bc6e0ceb210b900dd0414daf6 Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Fri, 5 Aug 2022 17:45:04 +0800 Subject: [PATCH 4/7] feat(Configuration): Add Global Configuration --- Masa.Framework.sln | 28 ++++++------- .../MasaConfigurationBuilderExtensions.cs} | 2 +- .../ServiceCollectionExtensions.cs | 0 .../WebApplicationBuilderExtensions.cs | 41 +++++++++++++++---- .../Internal/ConfigurationExtensions.cs | 6 +++ .../ConfigurationManagerExtensions.cs | 13 ------ .../{ => Options}/ConfigurationOptions.cs | 0 .../LocalMasaConfigurationOptions.cs | 0 .../MasaAppConfigureOptionsRelation.cs | 30 ++++++++++++++ .../{ => Options}/MasaRelationOptions.cs | 0 10 files changed, 85 insertions(+), 35 deletions(-) rename src/Contrib/Configuration/Masa.Contrib.Configuration/{MasaConfigurationExtensions.cs => Extensions/MasaConfigurationBuilderExtensions.cs} (97%) rename src/Contrib/Configuration/Masa.Contrib.Configuration/{ => Extensions}/ServiceCollectionExtensions.cs (100%) rename src/Contrib/Configuration/Masa.Contrib.Configuration/{ => Extensions}/WebApplicationBuilderExtensions.cs (64%) delete mode 100644 src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationManagerExtensions.cs rename src/Contrib/Configuration/Masa.Contrib.Configuration/{ => Options}/ConfigurationOptions.cs (100%) rename src/Contrib/Configuration/Masa.Contrib.Configuration/{ => Options}/LocalMasaConfigurationOptions.cs (100%) create mode 100644 src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaAppConfigureOptionsRelation.cs rename src/Contrib/Configuration/Masa.Contrib.Configuration/{ => Options}/MasaRelationOptions.cs (100%) diff --git a/Masa.Framework.sln b/Masa.Framework.sln index 9a658aae2..2425715d9 100644 --- a/Masa.Framework.sln +++ b/Masa.Framework.sln @@ -25,8 +25,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{E747043D-81E2-4A89-8B5B-1258ED45F941}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.EventBus.IntegrationTests", "test\Masa.EventBus.IntegrationTests\Masa.EventBus.IntegrationTests.csproj", "{BDA1DB4F-C408-445D-9391-EC9765CF7349}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Authentication", "Authentication", "{585B9627-45AA-42C3-965D-03359F25786C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenIdConnect", "OpenIdConnect", "{CFC8DE12-A06F-46E2-890A-6EC9400F17DA}" @@ -529,9 +527,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.UoW.EFCor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.UoW.EFCore.Tests", "src\Contrib\Data\UoW\Tests\Masa.Contrib.Data.UoW.EFCore.Tests\Masa.Contrib.Data.UoW.EFCore.Tests.csproj", "{8B19C9E6-002B-4DD4-8D80-9D092C3EA6E9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.Data.IdGenerator.Snowflake.Tests.Perfs", "src\Contrib\Data\IdGenerator\Snowflake\Tests\Perfs\Tests.Perfs\Masa.Contrib.Data.IdGenerator.Snowflake.Tests.Perfs.csproj", "{B37640C5-3F96-4363-915C-0C2848004A05}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.Snowflake.Tests.Perfs", "src\Contrib\Data\IdGenerator\Snowflake\Tests\Perfs\Tests.Perfs\Masa.Contrib.Data.IdGenerator.Snowflake.Tests.Perfs.csproj", "{B37640C5-3F96-4363-915C-0C2848004A05}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests.Perfs", "src\Contrib\Data\IdGenerator\Snowflake\Tests\Perfs\Distributed.Redis.Tests.Perfs\Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests.Perfs.csproj", "{9EA05A47-B28A-4CD1-8058-00A2098ED0C2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests.Perfs", "src\Contrib\Data\IdGenerator\Snowflake\Tests\Perfs\Distributed.Redis.Tests.Perfs\Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests.Perfs.csproj", "{9EA05A47-B28A-4CD1-8058-00A2098ED0C2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.EventBus.IntegrationTests", "test\Masa.EventBus.IntegrationTests\Masa.EventBus.IntegrationTests.csproj", "{A9EED08B-6C1E-4409-9874-AA7D34102519}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -541,14 +541,6 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {BDA1DB4F-C408-445D-9391-EC9765CF7349}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BDA1DB4F-C408-445D-9391-EC9765CF7349}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BDA1DB4F-C408-445D-9391-EC9765CF7349}.Debug|x64.ActiveCfg = Debug|Any CPU - {BDA1DB4F-C408-445D-9391-EC9765CF7349}.Debug|x64.Build.0 = Debug|Any CPU - {BDA1DB4F-C408-445D-9391-EC9765CF7349}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BDA1DB4F-C408-445D-9391-EC9765CF7349}.Release|Any CPU.Build.0 = Release|Any CPU - {BDA1DB4F-C408-445D-9391-EC9765CF7349}.Release|x64.ActiveCfg = Release|Any CPU - {BDA1DB4F-C408-445D-9391-EC9765CF7349}.Release|x64.Build.0 = Release|Any CPU {523EB315-1A01-4F13-9EDE-266FE8111AB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {523EB315-1A01-4F13-9EDE-266FE8111AB6}.Debug|Any CPU.Build.0 = Debug|Any CPU {523EB315-1A01-4F13-9EDE-266FE8111AB6}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -1885,6 +1877,14 @@ Global {9EA05A47-B28A-4CD1-8058-00A2098ED0C2}.Release|Any CPU.Build.0 = Release|Any CPU {9EA05A47-B28A-4CD1-8058-00A2098ED0C2}.Release|x64.ActiveCfg = Release|Any CPU {9EA05A47-B28A-4CD1-8058-00A2098ED0C2}.Release|x64.Build.0 = Release|Any CPU + {A9EED08B-6C1E-4409-9874-AA7D34102519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9EED08B-6C1E-4409-9874-AA7D34102519}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9EED08B-6C1E-4409-9874-AA7D34102519}.Debug|x64.ActiveCfg = Debug|Any CPU + {A9EED08B-6C1E-4409-9874-AA7D34102519}.Debug|x64.Build.0 = Debug|Any CPU + {A9EED08B-6C1E-4409-9874-AA7D34102519}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9EED08B-6C1E-4409-9874-AA7D34102519}.Release|Any CPU.Build.0 = Release|Any CPU + {A9EED08B-6C1E-4409-9874-AA7D34102519}.Release|x64.ActiveCfg = Release|Any CPU + {A9EED08B-6C1E-4409-9874-AA7D34102519}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1893,7 +1893,6 @@ Global {DC578D74-98F0-4F19-A230-CFA8DAEE0AF1} = {B9256C4D-86F4-4E67-8774-C3EF971EC811} {5944A182-13B8-4DA6-AEE2-0A01E64A9648} = {B9256C4D-86F4-4E67-8774-C3EF971EC811} {950DA7D0-48C1-42BA-8E8F-F72C0DCE41C4} = {B9256C4D-86F4-4E67-8774-C3EF971EC811} - {BDA1DB4F-C408-445D-9391-EC9765CF7349} = {E747043D-81E2-4A89-8B5B-1258ED45F941} {585B9627-45AA-42C3-965D-03359F25786C} = {DC578D74-98F0-4F19-A230-CFA8DAEE0AF1} {CFC8DE12-A06F-46E2-890A-6EC9400F17DA} = {585B9627-45AA-42C3-965D-03359F25786C} {87BBAEC2-1A18-4E5D-BDB3-91BF1CF3231B} = {DC578D74-98F0-4F19-A230-CFA8DAEE0AF1} @@ -2048,6 +2047,7 @@ Global {11B1DF36-97DC-4928-BED2-A51BDDFE0AEF} = {E676BB35-7888-4FCD-9AFA-E46848639074} {D77D8E17-6D1C-4E44-AF18-D572F12745BA} = {E676BB35-7888-4FCD-9AFA-E46848639074} {3167F949-F6F4-4440-97CD-2EC7B785D9E8} = {FFEF958B-DA21-4552-86B6-87D9592A3668} + {A00D752B-65C8-404A-8397-82DB5613884E} = {FFEF958B-DA21-4552-86B6-87D9592A3668} {17B751BF-DB79-46B0-A61E-BB8A52919AC9} = {FFEF958B-DA21-4552-86B6-87D9592A3668} {0457B5A1-02D7-44FF-8FE6-468A456E2909} = {17B751BF-DB79-46B0-A61E-BB8A52919AC9} {55DCA34D-48CE-4D32-8515-B6583FA548AE} = {17B751BF-DB79-46B0-A61E-BB8A52919AC9} @@ -2144,9 +2144,9 @@ Global {979FBAA7-EC54-4183-B2A7-3C5BE5510F16} = {83E5A183-56D6-4CAC-95A6-FB280AA7AE3D} {44DB6ED1-71DC-487B-8DD7-3F872CB23254} = {E8B3FB42-C450-4B12-9C2C-7B9A02B616BB} {8B19C9E6-002B-4DD4-8D80-9D092C3EA6E9} = {627DAA58-5882-4C65-B7A1-AE16AA91E1DE} - {A00D752B-65C8-404A-8397-82DB5613884E} = {FFEF958B-DA21-4552-86B6-87D9592A3668} {B37640C5-3F96-4363-915C-0C2848004A05} = {55DCA34D-48CE-4D32-8515-B6583FA548AE} {9EA05A47-B28A-4CD1-8058-00A2098ED0C2} = {55DCA34D-48CE-4D32-8515-B6583FA548AE} + {A9EED08B-6C1E-4409-9874-AA7D34102519} = {E747043D-81E2-4A89-8B5B-1258ED45F941} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {40383055-CC50-4600-AD9A-53C14F620D03} diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/MasaConfigurationExtensions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/MasaConfigurationBuilderExtensions.cs similarity index 97% rename from src/Contrib/Configuration/Masa.Contrib.Configuration/MasaConfigurationExtensions.cs rename to src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/MasaConfigurationBuilderExtensions.cs index 19e371e7b..8012df4d1 100644 --- a/src/Contrib/Configuration/Masa.Contrib.Configuration/MasaConfigurationExtensions.cs +++ b/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/MasaConfigurationBuilderExtensions.cs @@ -3,7 +3,7 @@ namespace Masa.Contrib.Configuration; -public static class MasaConfigurationExtensions +public static class MasaConfigurationBuilderExtensions { public static void UseMasaOptions(this IMasaConfigurationBuilder builder, Action options) { diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/ServiceCollectionExtensions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/ServiceCollectionExtensions.cs similarity index 100% rename from src/Contrib/Configuration/Masa.Contrib.Configuration/ServiceCollectionExtensions.cs rename to src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/ServiceCollectionExtensions.cs diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/WebApplicationBuilderExtensions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs similarity index 64% rename from src/Contrib/Configuration/Masa.Contrib.Configuration/WebApplicationBuilderExtensions.cs rename to src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs index 4b2135d83..0a350b943 100644 --- a/src/Contrib/Configuration/Masa.Contrib.Configuration/WebApplicationBuilderExtensions.cs +++ b/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs @@ -6,21 +6,41 @@ namespace Microsoft.AspNetCore.Builder; public static class WebApplicationBuilderExtensions { public static WebApplicationBuilder InitializeAppConfiguration(this WebApplicationBuilder builder) + => builder.InitializeAppConfiguration(null); + + public static WebApplicationBuilder InitializeAppConfiguration( + this WebApplicationBuilder builder, + Action? action) { - var configuration = builder.Configuration; + if (builder.Services.Any(service => service.ImplementationType == typeof(InitializeAppConfigurationProvider))) + return builder; + + builder.Services.AddSingleton(); + + MasaAppConfigureOptionsRelation optionsRelation = new(); + action?.Invoke(optionsRelation); + IConfiguration configuration = builder.Configuration; + bool isInitialize = false; builder.Services.Configure(options => { + if (!isInitialize) + { + var masaConfiguration = builder.Services.BuildServiceProvider().GetService(); + if (masaConfiguration != null) configuration = masaConfiguration.Local; + isInitialize = true; + } + if (string.IsNullOrWhiteSpace(options.AppId)) - options.AppId = configuration.GetConfigurationValue(nameof(MasaAppConfigureOptions.AppId), - () => (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName().Name!.Replace(".", "-")); + options.AppId = configuration.GetConfigurationValue(optionsRelation.DataVariables[nameof(options.AppId)], + () => optionsRelation.DataDefaultValue[nameof(options.AppId)]); if (string.IsNullOrWhiteSpace(options.Environment)) - options.Environment = configuration.GetConfigurationValue("ASPNETCORE_ENVIRONMENT", - () => "Production"); + options.Environment = configuration.GetConfigurationValue(optionsRelation.DataVariables[nameof(options.Environment)], + () => optionsRelation.DataDefaultValue[nameof(options.Environment)]); if (string.IsNullOrWhiteSpace(options.Cluster)) - options.Environment = configuration.GetConfigurationValue(nameof(MasaAppConfigureOptions.Cluster), - () => "Default"); + options.Cluster = configuration.GetConfigurationValue(optionsRelation.DataVariables[nameof(options.Cluster)], + () => optionsRelation.DataDefaultValue[nameof(options.Cluster)]); }); return builder; } @@ -58,6 +78,8 @@ public static WebApplicationBuilder AddMasaConfiguration( Action? configureDelegate, Action? action) { + builder.InitializeAppConfiguration(); + IConfigurationRoot masaConfiguration = builder.Services.CreateMasaConfiguration( configureDelegate, @@ -77,4 +99,9 @@ public static WebApplicationBuilder AddMasaConfiguration( public static IMasaConfiguration GetMasaConfiguration(this WebApplicationBuilder builder) => builder.Services.BuildServiceProvider().GetRequiredService(); + + private class InitializeAppConfigurationProvider + { + + } } diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationExtensions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationExtensions.cs index 958eb9ed7..297bb64a9 100644 --- a/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationExtensions.cs +++ b/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationExtensions.cs @@ -28,4 +28,10 @@ public static IConfigurationBuilder AddRange(this IConfigurationBuilder configur configurationBuilder.Add(configurationSource); return configurationBuilder; } + + public static string GetConfigurationValue(this IConfiguration configuration, string key, Func func) + { + var configurationValue = configuration[key]; + return string.IsNullOrWhiteSpace(configurationValue) ? func() : configurationValue; + } } diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationManagerExtensions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationManagerExtensions.cs deleted file mode 100644 index 2ebeddb08..000000000 --- a/src/Contrib/Configuration/Masa.Contrib.Configuration/Internal/ConfigurationManagerExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the MIT License. See LICENSE.txt in the project root for license information. - -namespace Masa.Contrib.Configuration.Internal; - -internal static class ConfigurationManagerExtensions -{ - public static string GetConfigurationValue(this ConfigurationManager configurationManager, string key, Func func) - { - var configurationValue = configurationManager[key]; - return string.IsNullOrWhiteSpace(configurationValue) ? func() : configurationValue; - } -} diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/ConfigurationOptions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/ConfigurationOptions.cs similarity index 100% rename from src/Contrib/Configuration/Masa.Contrib.Configuration/ConfigurationOptions.cs rename to src/Contrib/Configuration/Masa.Contrib.Configuration/Options/ConfigurationOptions.cs diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/LocalMasaConfigurationOptions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/LocalMasaConfigurationOptions.cs similarity index 100% rename from src/Contrib/Configuration/Masa.Contrib.Configuration/LocalMasaConfigurationOptions.cs rename to src/Contrib/Configuration/Masa.Contrib.Configuration/Options/LocalMasaConfigurationOptions.cs diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaAppConfigureOptionsRelation.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaAppConfigureOptionsRelation.cs new file mode 100644 index 000000000..49bc3dda0 --- /dev/null +++ b/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaAppConfigureOptionsRelation.cs @@ -0,0 +1,30 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.Configuration.Options; + +public class MasaAppConfigureOptionsRelation +{ + public Dictionary DataVariables { get; } + + public Dictionary DataDefaultValue { get; } + + public MasaAppConfigureOptionsRelation() + { + DataVariables = new() + { + { nameof(MasaAppConfigureOptions.AppId), nameof(MasaAppConfigureOptions.AppId) }, + { nameof(MasaAppConfigureOptions.Environment), "ASPNETCORE_ENVIRONMENT" }, + { nameof(MasaAppConfigureOptions.Cluster), nameof(MasaAppConfigureOptions.Cluster) }, + }; + DataDefaultValue = new Dictionary() + { + { + nameof(MasaAppConfigureOptions.AppId), + (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName().Name!.Replace(".", "-") + }, + { nameof(MasaAppConfigureOptions.Environment), "Production" }, + { nameof(MasaAppConfigureOptions.Cluster), "Default" }, + }; + } +} diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/MasaRelationOptions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaRelationOptions.cs similarity index 100% rename from src/Contrib/Configuration/Masa.Contrib.Configuration/MasaRelationOptions.cs rename to src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaRelationOptions.cs From f2e73e8b033d1f4db30a3b9c9f58e3f91dfab6b6 Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Mon, 8 Aug 2022 11:30:47 +0800 Subject: [PATCH 5/7] rename: Masa.EventBus.IntegrationTests rename to Masa.Framework.IntegrationTests.EventBus --- Masa.Framework.sln | 2 +- .../Application/Command/RegisterUserCommand.cs | 2 +- .../Application/Events/AddGoodsIntegrationEvent.cs | 2 +- .../Application/Events/RegisterUserEvent.cs | 2 +- .../Application/Queries/CheckUserQuery.cs | 2 +- .../Application/Queries/CheckUserQueryValidator.cs | 2 +- .../Application/Queries/UserAgeQuery.cs | 2 +- .../Application/Queries/UserAgeQueryValidator.cs | 2 +- .../Application/UserHandler.cs | 7 +------ .../Domain/Aggregate/User.cs | 2 +- .../Infrastructure/CustomDbContext.cs | 4 +--- .../Infrastructure/Extensions/DefaultPublisher.cs | 2 +- .../Extensions/DispatcherOptionsExtensions.cs | 2 +- .../Infrastructure/Middleware/RecordMiddleware.cs | 2 +- .../Infrastructure/Middleware/ValidatorMiddleware.cs | 2 +- .../Masa.Framework.IntegrationTests.EventBus.csproj} | 0 .../TestBase.cs | 6 +++++- .../TestDispatcher.cs | 6 +++++- .../_Imports.cs | 11 ++++------- 19 files changed, 29 insertions(+), 31 deletions(-) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Application/Command/RegisterUserCommand.cs (81%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Application/Events/AddGoodsIntegrationEvent.cs (86%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Application/Events/RegisterUserEvent.cs (78%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Application/Queries/CheckUserQuery.cs (79%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Application/Queries/CheckUserQueryValidator.cs (83%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Application/Queries/UserAgeQuery.cs (79%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Application/Queries/UserAgeQueryValidator.cs (83%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Application/UserHandler.cs (87%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Domain/Aggregate/User.cs (82%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Infrastructure/CustomDbContext.cs (74%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Infrastructure/Extensions/DefaultPublisher.cs (82%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Infrastructure/Extensions/DispatcherOptionsExtensions.cs (85%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Infrastructure/Middleware/RecordMiddleware.cs (85%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/Infrastructure/Middleware/ValidatorMiddleware.cs (92%) rename test/{Masa.EventBus.IntegrationTests/Masa.EventBus.IntegrationTests.csproj => Masa.Framework.IntegrationTests.EventBus/Masa.Framework.IntegrationTests.EventBus.csproj} (100%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/TestBase.cs (83%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/TestDispatcher.cs (91%) rename test/{Masa.EventBus.IntegrationTests => Masa.Framework.IntegrationTests.EventBus}/_Imports.cs (71%) diff --git a/Masa.Framework.sln b/Masa.Framework.sln index 2425715d9..9568abe23 100644 --- a/Masa.Framework.sln +++ b/Masa.Framework.sln @@ -531,7 +531,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerat EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests.Perfs", "src\Contrib\Data\IdGenerator\Snowflake\Tests\Perfs\Distributed.Redis.Tests.Perfs\Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests.Perfs.csproj", "{9EA05A47-B28A-4CD1-8058-00A2098ED0C2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.EventBus.IntegrationTests", "test\Masa.EventBus.IntegrationTests\Masa.EventBus.IntegrationTests.csproj", "{A9EED08B-6C1E-4409-9874-AA7D34102519}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Framework.IntegrationTests.EventBus", "test\Masa.Framework.IntegrationTests.EventBus\Masa.Framework.IntegrationTests.EventBus.csproj", "{A9EED08B-6C1E-4409-9874-AA7D34102519}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/test/Masa.EventBus.IntegrationTests/Application/Command/RegisterUserCommand.cs b/test/Masa.Framework.IntegrationTests.EventBus/Application/Command/RegisterUserCommand.cs similarity index 81% rename from test/Masa.EventBus.IntegrationTests/Application/Command/RegisterUserCommand.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Application/Command/RegisterUserCommand.cs index 258f34b1c..5f90fd0d4 100644 --- a/test/Masa.EventBus.IntegrationTests/Application/Command/RegisterUserCommand.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Application/Command/RegisterUserCommand.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Application.Command; +namespace Masa.Framework.IntegrationTests.EventBus.Application.Command; public record RegisterUserCommand : BuildingBlocks.ReadWriteSpliting.Cqrs.Commands.Command { diff --git a/test/Masa.EventBus.IntegrationTests/Application/Events/AddGoodsIntegrationEvent.cs b/test/Masa.Framework.IntegrationTests.EventBus/Application/Events/AddGoodsIntegrationEvent.cs similarity index 86% rename from test/Masa.EventBus.IntegrationTests/Application/Events/AddGoodsIntegrationEvent.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Application/Events/AddGoodsIntegrationEvent.cs index 7e9106990..b52043035 100644 --- a/test/Masa.EventBus.IntegrationTests/Application/Events/AddGoodsIntegrationEvent.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Application/Events/AddGoodsIntegrationEvent.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Application.Events; +namespace Masa.Framework.IntegrationTests.EventBus.Application.Events; public record AddGoodsIntegrationEvent : IntegrationEvent { diff --git a/test/Masa.EventBus.IntegrationTests/Application/Events/RegisterUserEvent.cs b/test/Masa.Framework.IntegrationTests.EventBus/Application/Events/RegisterUserEvent.cs similarity index 78% rename from test/Masa.EventBus.IntegrationTests/Application/Events/RegisterUserEvent.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Application/Events/RegisterUserEvent.cs index 6fa6183a0..0bca53d28 100644 --- a/test/Masa.EventBus.IntegrationTests/Application/Events/RegisterUserEvent.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Application/Events/RegisterUserEvent.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Application.Events; +namespace Masa.Framework.IntegrationTests.EventBus.Application.Events; public record RegisterUserEvent : Event { diff --git a/test/Masa.EventBus.IntegrationTests/Application/Queries/CheckUserQuery.cs b/test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/CheckUserQuery.cs similarity index 79% rename from test/Masa.EventBus.IntegrationTests/Application/Queries/CheckUserQuery.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/CheckUserQuery.cs index eab124c93..e43964af6 100644 --- a/test/Masa.EventBus.IntegrationTests/Application/Queries/CheckUserQuery.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/CheckUserQuery.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Application.Queries; +namespace Masa.Framework.IntegrationTests.EventBus.Application.Queries; public record CheckUserQuery : Query { diff --git a/test/Masa.EventBus.IntegrationTests/Application/Queries/CheckUserQueryValidator.cs b/test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/CheckUserQueryValidator.cs similarity index 83% rename from test/Masa.EventBus.IntegrationTests/Application/Queries/CheckUserQueryValidator.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/CheckUserQueryValidator.cs index ad2ec783b..d7255d017 100644 --- a/test/Masa.EventBus.IntegrationTests/Application/Queries/CheckUserQueryValidator.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/CheckUserQueryValidator.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Application.Queries; +namespace Masa.Framework.IntegrationTests.EventBus.Application.Queries; public class CheckUserQueryValidator : AbstractValidator { diff --git a/test/Masa.EventBus.IntegrationTests/Application/Queries/UserAgeQuery.cs b/test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/UserAgeQuery.cs similarity index 79% rename from test/Masa.EventBus.IntegrationTests/Application/Queries/UserAgeQuery.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/UserAgeQuery.cs index 767019652..172807102 100644 --- a/test/Masa.EventBus.IntegrationTests/Application/Queries/UserAgeQuery.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/UserAgeQuery.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Application.Queries; +namespace Masa.Framework.IntegrationTests.EventBus.Application.Queries; public record UserAgeQuery : Query { diff --git a/test/Masa.EventBus.IntegrationTests/Application/Queries/UserAgeQueryValidator.cs b/test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/UserAgeQueryValidator.cs similarity index 83% rename from test/Masa.EventBus.IntegrationTests/Application/Queries/UserAgeQueryValidator.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/UserAgeQueryValidator.cs index 6355c3c78..6ed387503 100644 --- a/test/Masa.EventBus.IntegrationTests/Application/Queries/UserAgeQueryValidator.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Application/Queries/UserAgeQueryValidator.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Application.Queries; +namespace Masa.Framework.IntegrationTests.EventBus.Application.Queries; public class UserAgeQueryValidator: AbstractValidator { diff --git a/test/Masa.EventBus.IntegrationTests/Application/UserHandler.cs b/test/Masa.Framework.IntegrationTests.EventBus/Application/UserHandler.cs similarity index 87% rename from test/Masa.EventBus.IntegrationTests/Application/UserHandler.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Application/UserHandler.cs index d23c68ab4..5dd13e8c0 100644 --- a/test/Masa.EventBus.IntegrationTests/Application/UserHandler.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Application/UserHandler.cs @@ -1,12 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -using Masa.EventBus.IntegrationTests.Application.Command; -using Masa.EventBus.IntegrationTests.Application.Events; -using Masa.EventBus.IntegrationTests.Application.Queries; -using Masa.EventBus.IntegrationTests.Domain.Aggregate; - -namespace Masa.EventBus.IntegrationTests.Application; +namespace Masa.Framework.IntegrationTests.EventBus.Application; public class UserHandler { diff --git a/test/Masa.EventBus.IntegrationTests/Domain/Aggregate/User.cs b/test/Masa.Framework.IntegrationTests.EventBus/Domain/Aggregate/User.cs similarity index 82% rename from test/Masa.EventBus.IntegrationTests/Domain/Aggregate/User.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Domain/Aggregate/User.cs index 1fd986461..736ecd83f 100644 --- a/test/Masa.EventBus.IntegrationTests/Domain/Aggregate/User.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Domain/Aggregate/User.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Domain.Aggregate; +namespace Masa.Framework.IntegrationTests.EventBus.Domain.Aggregate; public class User : AggregateRoot { diff --git a/test/Masa.EventBus.IntegrationTests/Infrastructure/CustomDbContext.cs b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/CustomDbContext.cs similarity index 74% rename from test/Masa.EventBus.IntegrationTests/Infrastructure/CustomDbContext.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/CustomDbContext.cs index e898bd894..758f4675d 100644 --- a/test/Masa.EventBus.IntegrationTests/Infrastructure/CustomDbContext.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/CustomDbContext.cs @@ -1,9 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -using Masa.EventBus.IntegrationTests.Domain.Aggregate; - -namespace Masa.EventBus.IntegrationTests.Infrastructure; +namespace Masa.Framework.IntegrationTests.EventBus.Infrastructure; public class CustomDbContext : MasaDbContext { diff --git a/test/Masa.EventBus.IntegrationTests/Infrastructure/Extensions/DefaultPublisher.cs b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Extensions/DefaultPublisher.cs similarity index 82% rename from test/Masa.EventBus.IntegrationTests/Infrastructure/Extensions/DefaultPublisher.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Extensions/DefaultPublisher.cs index e016c2f22..96b7693d6 100644 --- a/test/Masa.EventBus.IntegrationTests/Infrastructure/Extensions/DefaultPublisher.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Extensions/DefaultPublisher.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Infrastructure.Extensions; +namespace Masa.Framework.IntegrationTests.EventBus.Infrastructure.Extensions; public class DefaultPublisher : IPublisher { diff --git a/test/Masa.EventBus.IntegrationTests/Infrastructure/Extensions/DispatcherOptionsExtensions.cs b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Extensions/DispatcherOptionsExtensions.cs similarity index 85% rename from test/Masa.EventBus.IntegrationTests/Infrastructure/Extensions/DispatcherOptionsExtensions.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Extensions/DispatcherOptionsExtensions.cs index 83a0da8ae..714cb5cd2 100644 --- a/test/Masa.EventBus.IntegrationTests/Infrastructure/Extensions/DispatcherOptionsExtensions.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Extensions/DispatcherOptionsExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Infrastructure.Extensions; +namespace Masa.Framework.IntegrationTests.EventBus.Infrastructure.Extensions; public static class DispatcherOptionsExtensions { diff --git a/test/Masa.EventBus.IntegrationTests/Infrastructure/Middleware/RecordMiddleware.cs b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Middleware/RecordMiddleware.cs similarity index 85% rename from test/Masa.EventBus.IntegrationTests/Infrastructure/Middleware/RecordMiddleware.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Middleware/RecordMiddleware.cs index b3deb4d9d..ad4774d9d 100644 --- a/test/Masa.EventBus.IntegrationTests/Infrastructure/Middleware/RecordMiddleware.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Middleware/RecordMiddleware.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Infrastructure.Middleware; +namespace Masa.Framework.IntegrationTests.EventBus.Infrastructure.Middleware; public class RecordMiddleware : Middleware where TEvent : IEvent diff --git a/test/Masa.EventBus.IntegrationTests/Infrastructure/Middleware/ValidatorMiddleware.cs b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Middleware/ValidatorMiddleware.cs similarity index 92% rename from test/Masa.EventBus.IntegrationTests/Infrastructure/Middleware/ValidatorMiddleware.cs rename to test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Middleware/ValidatorMiddleware.cs index 1c4b8f321..a635af4f2 100644 --- a/test/Masa.EventBus.IntegrationTests/Infrastructure/Middleware/ValidatorMiddleware.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/Infrastructure/Middleware/ValidatorMiddleware.cs @@ -1,7 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests.Infrastructure.Middleware; +namespace Masa.Framework.IntegrationTests.EventBus.Infrastructure.Middleware; public class ValidatorMiddleware : Middleware where TEvent : notnull, IEvent diff --git a/test/Masa.EventBus.IntegrationTests/Masa.EventBus.IntegrationTests.csproj b/test/Masa.Framework.IntegrationTests.EventBus/Masa.Framework.IntegrationTests.EventBus.csproj similarity index 100% rename from test/Masa.EventBus.IntegrationTests/Masa.EventBus.IntegrationTests.csproj rename to test/Masa.Framework.IntegrationTests.EventBus/Masa.Framework.IntegrationTests.EventBus.csproj diff --git a/test/Masa.EventBus.IntegrationTests/TestBase.cs b/test/Masa.Framework.IntegrationTests.EventBus/TestBase.cs similarity index 83% rename from test/Masa.EventBus.IntegrationTests/TestBase.cs rename to test/Masa.Framework.IntegrationTests.EventBus/TestBase.cs index 8f05a6bdc..bb5bf2735 100644 --- a/test/Masa.EventBus.IntegrationTests/TestBase.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/TestBase.cs @@ -1,7 +1,11 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests; +using Masa.Framework.IntegrationTests.EventBus.Infrastructure; +using Masa.Framework.IntegrationTests.EventBus.Infrastructure.Extensions; +using Masa.Framework.IntegrationTests.EventBus.Infrastructure.Middleware; + +namespace Masa.Framework.IntegrationTests.EventBus; [TestClass] public class TestBase diff --git a/test/Masa.EventBus.IntegrationTests/TestDispatcher.cs b/test/Masa.Framework.IntegrationTests.EventBus/TestDispatcher.cs similarity index 91% rename from test/Masa.EventBus.IntegrationTests/TestDispatcher.cs rename to test/Masa.Framework.IntegrationTests.EventBus/TestDispatcher.cs index 72e4f1ca4..96194fbd7 100644 --- a/test/Masa.EventBus.IntegrationTests/TestDispatcher.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/TestDispatcher.cs @@ -1,7 +1,11 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the MIT License. See LICENSE.txt in the project root for license information. -namespace Masa.EventBus.IntegrationTests; +using Masa.Framework.IntegrationTests.EventBus.Infrastructure; +using Masa.Framework.IntegrationTests.EventBus.Infrastructure.Extensions; +using Masa.Framework.IntegrationTests.EventBus.Infrastructure.Middleware; + +namespace Masa.Framework.IntegrationTests.EventBus; [TestClass] public class TestDispatcher : TestBase diff --git a/test/Masa.EventBus.IntegrationTests/_Imports.cs b/test/Masa.Framework.IntegrationTests.EventBus/_Imports.cs similarity index 71% rename from test/Masa.EventBus.IntegrationTests/_Imports.cs rename to test/Masa.Framework.IntegrationTests.EventBus/_Imports.cs index 59cb9e21f..dd0c1fde3 100644 --- a/test/Masa.EventBus.IntegrationTests/_Imports.cs +++ b/test/Masa.Framework.IntegrationTests.EventBus/_Imports.cs @@ -16,13 +16,10 @@ global using Masa.Contrib.Dispatcher.Events; global using Masa.Contrib.Dispatcher.IntegrationEvents; global using Masa.Contrib.Dispatcher.IntegrationEvents.EventLogs.EFCore; -global using Masa.EventBus.IntegrationTests.Application.Command; -global using Masa.EventBus.IntegrationTests.Application.Events; -global using Masa.EventBus.IntegrationTests.Application.Queries; -global using Masa.EventBus.IntegrationTests.Domain.Aggregate; -global using Masa.EventBus.IntegrationTests.Infrastructure; -global using Masa.EventBus.IntegrationTests.Infrastructure.Extensions; -global using Masa.EventBus.IntegrationTests.Infrastructure.Middleware; +global using Masa.Framework.IntegrationTests.EventBus.Application.Command; +global using Masa.Framework.IntegrationTests.EventBus.Application.Events; +global using Masa.Framework.IntegrationTests.EventBus.Application.Queries; +global using Masa.Framework.IntegrationTests.EventBus.Domain.Aggregate; global using Microsoft.EntityFrameworkCore; global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Extensions.DependencyInjection.Extensions; From 62420a2dd3c3e75d50ea997af0c9c608537e21cd Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Mon, 8 Aug 2022 13:18:11 +0800 Subject: [PATCH 6/7] refactor(Configuration): Adjust default variables and default values --- .../Options/MasaAppConfigureOptions.cs | 13 +++++++--- .../WebApplicationBuilderExtensions.cs | 18 ++++++------- .../MasaAppConfigureOptionsRelation.cs | 25 +++++++++--------- .../WebApplicationBuilderTest.cs | 26 +++++++++++++++++++ .../_Imports.cs | 1 + 5 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 src/Contrib/Configuration/Tests/Masa.Contrib.Configuration.Tests/WebApplicationBuilderTest.cs diff --git a/src/BuildingBlocks/Configuration/Masa.BuildingBlocks.Configuration/Options/MasaAppConfigureOptions.cs b/src/BuildingBlocks/Configuration/Masa.BuildingBlocks.Configuration/Options/MasaAppConfigureOptions.cs index c2b814864..1946cd609 100644 --- a/src/BuildingBlocks/Configuration/Masa.BuildingBlocks.Configuration/Options/MasaAppConfigureOptions.cs +++ b/src/BuildingBlocks/Configuration/Masa.BuildingBlocks.Configuration/Options/MasaAppConfigureOptions.cs @@ -5,11 +5,18 @@ namespace Masa.BuildingBlocks.Configuration.Options; public class MasaAppConfigureOptions { - public string AppId { get; set; } + public string AppId { get => GetValue(nameof(AppId)); set => Data[nameof(AppId)] = value; } - public string Environment { get; set; } + public string Environment { get => GetValue(nameof(Environment)); set => Data[nameof(Environment)] = value; } - public string Cluster { get; set; } + public string Cluster { get => GetValue(nameof(Cluster)); set => Data[nameof(Cluster)] = value; } public Dictionary Data { get; set; } = new(); + + private string GetValue(string key) + { + if (Data.ContainsKey(key)) return Data[key]; + + return string.Empty; + } } diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs index 0a350b943..5507e3dc7 100644 --- a/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs +++ b/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs @@ -20,27 +20,27 @@ public static WebApplicationBuilder InitializeAppConfiguration( MasaAppConfigureOptionsRelation optionsRelation = new(); action?.Invoke(optionsRelation); IConfiguration configuration = builder.Configuration; - bool isInitialize = false; + bool initialized = false; builder.Services.Configure(options => { - if (!isInitialize) + if (!initialized) { var masaConfiguration = builder.Services.BuildServiceProvider().GetService(); if (masaConfiguration != null) configuration = masaConfiguration.Local; - isInitialize = true; + initialized = true; } if (string.IsNullOrWhiteSpace(options.AppId)) - options.AppId = configuration.GetConfigurationValue(optionsRelation.DataVariables[nameof(options.AppId)], - () => optionsRelation.DataDefaultValue[nameof(options.AppId)]); + options.AppId = configuration.GetConfigurationValue(optionsRelation.Data[nameof(options.AppId)].Variable, + () => optionsRelation.Data[nameof(options.AppId)].DefaultValue); if (string.IsNullOrWhiteSpace(options.Environment)) - options.Environment = configuration.GetConfigurationValue(optionsRelation.DataVariables[nameof(options.Environment)], - () => optionsRelation.DataDefaultValue[nameof(options.Environment)]); + options.Environment = configuration.GetConfigurationValue(optionsRelation.Data[nameof(options.Environment)].Variable, + () => optionsRelation.Data[nameof(options.Environment)].DefaultValue); if (string.IsNullOrWhiteSpace(options.Cluster)) - options.Cluster = configuration.GetConfigurationValue(optionsRelation.DataVariables[nameof(options.Cluster)], - () => optionsRelation.DataDefaultValue[nameof(options.Cluster)]); + options.Cluster = configuration.GetConfigurationValue(optionsRelation.Data[nameof(options.Cluster)].Variable, + () => optionsRelation.Data[nameof(options.Cluster)].DefaultValue); }); return builder; } diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaAppConfigureOptionsRelation.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaAppConfigureOptionsRelation.cs index 49bc3dda0..a8436ff65 100644 --- a/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaAppConfigureOptionsRelation.cs +++ b/src/Contrib/Configuration/Masa.Contrib.Configuration/Options/MasaAppConfigureOptionsRelation.cs @@ -5,26 +5,25 @@ namespace Masa.BuildingBlocks.Configuration.Options; public class MasaAppConfigureOptionsRelation { - public Dictionary DataVariables { get; } - - public Dictionary DataDefaultValue { get; } + public Dictionary Data { get; set; } public MasaAppConfigureOptionsRelation() { - DataVariables = new() - { - { nameof(MasaAppConfigureOptions.AppId), nameof(MasaAppConfigureOptions.AppId) }, - { nameof(MasaAppConfigureOptions.Environment), "ASPNETCORE_ENVIRONMENT" }, - { nameof(MasaAppConfigureOptions.Cluster), nameof(MasaAppConfigureOptions.Cluster) }, - }; - DataDefaultValue = new Dictionary() + Data = new Dictionary() { { nameof(MasaAppConfigureOptions.AppId), - (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName().Name!.Replace(".", "-") + (nameof(MasaAppConfigureOptions.AppId), + (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName().Name!.Replace(".", "-")) }, - { nameof(MasaAppConfigureOptions.Environment), "Production" }, - { nameof(MasaAppConfigureOptions.Cluster), "Default" }, + { + nameof(MasaAppConfigureOptions.Environment), + ("ASPNETCORE_ENVIRONMENT", "Production") + }, + { + nameof(MasaAppConfigureOptions.Cluster), + (nameof(MasaAppConfigureOptions.Cluster), "Default") + } }; } } diff --git a/src/Contrib/Configuration/Tests/Masa.Contrib.Configuration.Tests/WebApplicationBuilderTest.cs b/src/Contrib/Configuration/Tests/Masa.Contrib.Configuration.Tests/WebApplicationBuilderTest.cs new file mode 100644 index 000000000..2698526c8 --- /dev/null +++ b/src/Contrib/Configuration/Tests/Masa.Contrib.Configuration.Tests/WebApplicationBuilderTest.cs @@ -0,0 +1,26 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.Contrib.Configuration.Tests; + +[TestClass] +public class WebApplicationBuilderTest +{ + [TestMethod] + public void TestInitializeAppConfiguration() + { + var builder = WebApplication.CreateBuilder(); + string env = "Development"; + builder.Services.Configure(options => + { + options.Environment = env; + }); + builder.InitializeAppConfiguration(); + var serviceProvider = builder.Services.BuildServiceProvider(); + var masaAppConfigureOptions = serviceProvider.GetService>()!; + + Assert.IsTrue(masaAppConfigureOptions.Value.Data.Count == 3); + Assert.IsTrue(masaAppConfigureOptions.Value.Environment == env); + Assert.IsTrue(masaAppConfigureOptions.Value.Data[nameof(MasaAppConfigureOptions.Environment)] == env); + } +} diff --git a/src/Contrib/Configuration/Tests/Masa.Contrib.Configuration.Tests/_Imports.cs b/src/Contrib/Configuration/Tests/Masa.Contrib.Configuration.Tests/_Imports.cs index a1380098e..0c6ca6d6c 100644 --- a/src/Contrib/Configuration/Tests/Masa.Contrib.Configuration.Tests/_Imports.cs +++ b/src/Contrib/Configuration/Tests/Masa.Contrib.Configuration.Tests/_Imports.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See LICENSE.txt in the project root for license information. global using Masa.BuildingBlocks.Configuration; +global using Masa.BuildingBlocks.Configuration.Options; global using Masa.Contrib.Configuration.Tests.Config; global using Masa.Contrib.Configuration.Tests.Scenes.AutoMap; global using Masa.Contrib.Configuration.Tests.Scenes.NoLessConstructor; From 5538161abc6e5121c33f261f7f89179b18e133fc Mon Sep 17 00:00:00 2001 From: zhenlei520 Date: Mon, 8 Aug 2022 18:16:01 +0800 Subject: [PATCH 7/7] chroe: delete extra space --- .../Extensions/WebApplicationBuilderExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs b/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs index 5507e3dc7..fe73a96b1 100644 --- a/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs +++ b/src/Contrib/Configuration/Masa.Contrib.Configuration/Extensions/WebApplicationBuilderExtensions.cs @@ -32,7 +32,7 @@ public static WebApplicationBuilder InitializeAppConfiguration( if (string.IsNullOrWhiteSpace(options.AppId)) options.AppId = configuration.GetConfigurationValue(optionsRelation.Data[nameof(options.AppId)].Variable, - () => optionsRelation.Data[nameof(options.AppId)].DefaultValue); + () => optionsRelation.Data[nameof(options.AppId)].DefaultValue); if (string.IsNullOrWhiteSpace(options.Environment)) options.Environment = configuration.GetConfigurationValue(optionsRelation.Data[nameof(options.Environment)].Variable,