Introdce the `IApplicationConfigurationContributor`.

Resolve #13099
pull/13100/head
maliming 3 years ago
parent ea7ee98937
commit c457e1f359
No known key found for this signature in database
GPG Key ID: 096224957E51C89E

@ -0,0 +1,13 @@
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
public class AbpApplicationConfigurationOptions
{
public List<IApplicationConfigurationContributor> Contributors { get; }
public AbpApplicationConfigurationOptions()
{
Contributors = new List<IApplicationConfigurationContributor>();
}
}

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

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

@ -0,0 +1,8 @@
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
public interface IApplicationConfigurationContributor
{
Task ContributeAsync(ApplicationConfigurationContributorContext context);
}

@ -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<AbpLocalizationOptions> localizationOptions,
@ -58,7 +59,8 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp
ILanguageProvider languageProvider,
ITimezoneProvider timezoneProvider,
IOptions<AbpClockOptions> abpClockOptions,
ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService)
ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService,
IOptions<AbpApplicationConfigurationOptions> 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;

@ -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<AbpApplicationConfigurationOptions>(options =>
{
options.Contributors.Add(new TestApplicationConfigurationContributor());
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)

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

@ -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;
}
}
Loading…
Cancel
Save