Browse Source

Introdce the `IApplicationConfigurationContributor`.

Resolve #13099
pull/13100/head
maliming 4 years ago
parent
commit
c457e1f359
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 13
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationOptions.cs
  2. 17
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationContributorContext.cs
  3. 3
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs
  4. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IApplicationConfigurationContributor.cs
  5. 17
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs
  6. 6
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs
  7. 2
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs
  8. 13
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/TestApplicationConfigurationContributor.cs

13
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<IApplicationConfigurationContributor> Contributors { get; }
public AbpApplicationConfigurationOptions()
{
Contributors = new List<IApplicationConfigurationContributor>();
}
}

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

3
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs

@ -1,11 +1,12 @@
using System; using System;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
using Volo.Abp.AspNetCore.Mvc.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.MultiTenancy;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
[Serializable] [Serializable]
public class ApplicationConfigurationDto public class ApplicationConfigurationDto : ExtensibleObject
{ {
public ApplicationLocalizationConfigurationDto Localization { get; set; } public ApplicationLocalizationConfigurationDto Localization { get; set; }

8
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);
}

17
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 ITimezoneProvider _timezoneProvider;
private readonly AbpClockOptions _abpClockOptions; private readonly AbpClockOptions _abpClockOptions;
private readonly ICachedObjectExtensionsDtoService _cachedObjectExtensionsDtoService; private readonly ICachedObjectExtensionsDtoService _cachedObjectExtensionsDtoService;
private readonly AbpApplicationConfigurationOptions _options;
public AbpApplicationConfigurationAppService( public AbpApplicationConfigurationAppService(
IOptions<AbpLocalizationOptions> localizationOptions, IOptions<AbpLocalizationOptions> localizationOptions,
@ -58,7 +59,8 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp
ILanguageProvider languageProvider, ILanguageProvider languageProvider,
ITimezoneProvider timezoneProvider, ITimezoneProvider timezoneProvider,
IOptions<AbpClockOptions> abpClockOptions, IOptions<AbpClockOptions> abpClockOptions,
ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService) ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService,
IOptions<AbpApplicationConfigurationOptions> options)
{ {
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_abpAuthorizationPolicyProvider = abpAuthorizationPolicyProvider; _abpAuthorizationPolicyProvider = abpAuthorizationPolicyProvider;
@ -74,6 +76,7 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp
_timezoneProvider = timezoneProvider; _timezoneProvider = timezoneProvider;
_abpClockOptions = abpClockOptions.Value; _abpClockOptions = abpClockOptions.Value;
_cachedObjectExtensionsDtoService = cachedObjectExtensionsDtoService; _cachedObjectExtensionsDtoService = cachedObjectExtensionsDtoService;
_options = options.Value;
_localizationOptions = localizationOptions.Value; _localizationOptions = localizationOptions.Value;
_multiTenancyOptions = multiTenancyOptions.Value; _multiTenancyOptions = multiTenancyOptions.Value;
} }
@ -99,6 +102,18 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp
ObjectExtensions = _cachedObjectExtensionsDtoService.Get() 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()."); Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetAsync().");
return result; return result;

6
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.Razor;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
using Volo.Abp.AspNetCore.Mvc.Authorization; using Volo.Abp.AspNetCore.Mvc.Authorization;
using Volo.Abp.AspNetCore.Mvc.GlobalFeatures; using Volo.Abp.AspNetCore.Mvc.GlobalFeatures;
using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.Localization;
@ -127,6 +128,11 @@ public class AbpAspNetCoreMvcTestModule : AbpModule
options.Maps.Add("SerialNumber", () => ClaimTypes.SerialNumber); options.Maps.Add("SerialNumber", () => ClaimTypes.SerialNumber);
options.Maps.Add("DateOfBirth", () => ClaimTypes.DateOfBirth); options.Maps.Add("DateOfBirth", () => ClaimTypes.DateOfBirth);
}); });
Configure<AbpApplicationConfigurationOptions>(options =>
{
options.Contributors.Add(new TestApplicationConfigurationContributor());
});
} }
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)

2
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs

@ -1,5 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Shouldly; using Shouldly;
using Volo.Abp.Data;
using Xunit; using Xunit;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
@ -15,5 +16,6 @@ public class ApplicationConfigurationBuilder_Tests : AspNetCoreMvcTestBase
config.Auth.ShouldNotBeNull(); config.Auth.ShouldNotBeNull();
config.Localization.ShouldNotBeNull(); config.Localization.ShouldNotBeNull();
config.GetProperty("TestKey").ShouldBe("TestValue");
} }
} }

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