Browse Source

Merge pull request #13100 from abpframework/IApplicationConfigurationContributor

Introduce the `IApplicationConfigurationContributor`.
pull/13126/head
Berkan Sasmaz 4 years ago
committed by GitHub
parent
commit
f82c41c7cf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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. 5
      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. 21
      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;
}
}

5
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.Data;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
[Serializable] [Serializable]
public class ApplicationConfigurationDto public class ApplicationConfigurationDto : IHasExtraProperties
{ {
public ApplicationLocalizationConfigurationDto Localization { get; set; } public ApplicationLocalizationConfigurationDto Localization { get; set; }
@ -28,4 +29,6 @@ public class ApplicationConfigurationDto
public ClockDto Clock { get; set; } public ClockDto Clock { get; set; }
public ObjectExtensionsDto ObjectExtensions { get; set; } public ObjectExtensionsDto ObjectExtensions { get; set; }
public ExtraPropertyDictionary ExtraProperties { 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);
}

21
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs

@ -13,6 +13,7 @@ using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
using Volo.Abp.AspNetCore.Mvc.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.MultiTenancy;
using Volo.Abp.Authorization; using Volo.Abp.Authorization;
using Volo.Abp.Authorization.Permissions; using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Data;
using Volo.Abp.Features; using Volo.Abp.Features;
using Volo.Abp.GlobalFeatures; using Volo.Abp.GlobalFeatures;
using Volo.Abp.Localization; using Volo.Abp.Localization;
@ -41,6 +42,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 +60,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 +77,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;
} }
@ -96,9 +100,22 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp
CurrentTenant = GetCurrentTenant(), CurrentTenant = GetCurrentTenant(),
Timing = await GetTimingConfigAsync(), Timing = await GetTimingConfigAsync(),
Clock = GetClockConfig(), Clock = GetClockConfig(),
ObjectExtensions = _cachedObjectExtensionsDtoService.Get() ObjectExtensions = _cachedObjectExtensionsDtoService.Get(),
ExtraProperties = new ExtraPropertyDictionary()
}; };
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