diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationOptions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationOptions.cs new file mode 100644 index 0000000000..e4e59bc197 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationOptions.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; + +public class AbpApplicationConfigurationOptions +{ + public List Contributors { get; } + + public AbpApplicationConfigurationOptions() + { + Contributors = new List(); + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationContributorContext.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationContributorContext.cs new file mode 100644 index 0000000000..3831cc1618 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationContributorContext.cs @@ -0,0 +1,17 @@ +using System; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; + +public class ApplicationConfigurationContributorContext : IServiceProviderAccessor +{ + public IServiceProvider ServiceProvider { get; } + + public ApplicationConfigurationDto ApplicationConfiguration { get; } + + public ApplicationConfigurationContributorContext(IServiceProvider serviceProvider, ApplicationConfigurationDto applicationConfiguration) + { + ServiceProvider = serviceProvider; + ApplicationConfiguration = applicationConfiguration; + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs index eb29c5c7cb..4a7a21959f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs @@ -1,11 +1,12 @@ using System; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; using Volo.Abp.AspNetCore.Mvc.MultiTenancy; +using Volo.Abp.ObjectExtending; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; [Serializable] -public class ApplicationConfigurationDto +public class ApplicationConfigurationDto : ExtensibleObject { public ApplicationLocalizationConfigurationDto Localization { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IApplicationConfigurationContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IApplicationConfigurationContributor.cs new file mode 100644 index 0000000000..7612ae6fec --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IApplicationConfigurationContributor.cs @@ -0,0 +1,8 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; + +public interface IApplicationConfigurationContributor +{ + Task ContributeAsync(ApplicationConfigurationContributorContext context); +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index b80a288e81..abf3fe603c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -41,6 +41,7 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp private readonly ITimezoneProvider _timezoneProvider; private readonly AbpClockOptions _abpClockOptions; private readonly ICachedObjectExtensionsDtoService _cachedObjectExtensionsDtoService; + private readonly AbpApplicationConfigurationOptions _options; public AbpApplicationConfigurationAppService( IOptions localizationOptions, @@ -58,7 +59,8 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp ILanguageProvider languageProvider, ITimezoneProvider timezoneProvider, IOptions abpClockOptions, - ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService) + ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService, + IOptions options) { _serviceProvider = serviceProvider; _abpAuthorizationPolicyProvider = abpAuthorizationPolicyProvider; @@ -74,6 +76,7 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp _timezoneProvider = timezoneProvider; _abpClockOptions = abpClockOptions.Value; _cachedObjectExtensionsDtoService = cachedObjectExtensionsDtoService; + _options = options.Value; _localizationOptions = localizationOptions.Value; _multiTenancyOptions = multiTenancyOptions.Value; } @@ -99,6 +102,18 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp ObjectExtensions = _cachedObjectExtensionsDtoService.Get() }; + if (_options.Contributors.Any()) + { + using (var scope = _serviceProvider.CreateScope()) + { + var context = new ApplicationConfigurationContributorContext(scope.ServiceProvider, result); + foreach (var contributor in _options.Contributors) + { + await contributor.ContributeAsync(context); + } + } + } + Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetAsync()."); return result; diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs index 2e8d8c4689..e303a0fb5d 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.AspNetCore.Mvc.Authorization; using Volo.Abp.AspNetCore.Mvc.GlobalFeatures; using Volo.Abp.AspNetCore.Mvc.Localization; @@ -127,6 +128,11 @@ public class AbpAspNetCoreMvcTestModule : AbpModule options.Maps.Add("SerialNumber", () => ClaimTypes.SerialNumber); options.Maps.Add("DateOfBirth", () => ClaimTypes.DateOfBirth); }); + + Configure(options => + { + options.Contributors.Add(new TestApplicationConfigurationContributor()); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs index c932e09488..5d3cb09749 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Shouldly; +using Volo.Abp.Data; using Xunit; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; @@ -15,5 +16,6 @@ public class ApplicationConfigurationBuilder_Tests : AspNetCoreMvcTestBase config.Auth.ShouldNotBeNull(); config.Localization.ShouldNotBeNull(); + config.GetProperty("TestKey").ShouldBe("TestValue"); } } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/TestApplicationConfigurationContributor.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/TestApplicationConfigurationContributor.cs new file mode 100644 index 0000000000..4ae197d2a0 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/TestApplicationConfigurationContributor.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; +using Volo.Abp.Data; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; + +public class TestApplicationConfigurationContributor : IApplicationConfigurationContributor +{ + public Task ContributeAsync(ApplicationConfigurationContributorContext context) + { + context.ApplicationConfiguration.SetProperty("TestKey", "TestValue"); + return Task.CompletedTask; + } +}