From 34f68c27c4e3bf28ce265a5fe2e7c248b0af32ea Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Tue, 12 Feb 2019 15:14:33 +0300 Subject: [PATCH] Add a simple setting example. --- .../PublicWebSite.Host/Pages/Products.cshtml | 8 ++++++- .../Pages/Products.cshtml.cs | 1 - .../IPublicProductAppService.cs | 3 +-- ...uctManagementApplicationContractsModule.cs | 6 +++++ ...ductManagementSettingDefinitionProvider.cs | 22 +++++++++++++++++++ .../ProductManagementSettings.cs | 12 ++++++++++ .../ProductManagement/ProductAppService.cs | 15 ++++++++++--- .../ProductManagementApplicationModule.cs | 6 ----- ...ductManagementSettingDefinitionProvider.cs | 14 ------------ .../ProductManagementSettings.cs | 11 ---------- .../PublicProductAppService.cs | 3 +-- 11 files changed, 61 insertions(+), 40 deletions(-) create mode 100644 samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettingDefinitionProvider.cs create mode 100644 samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettings.cs delete mode 100644 samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettingDefinitionProvider.cs delete mode 100644 samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettings.cs diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml b/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml index a89f786992..4165781b58 100644 --- a/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml +++ b/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml @@ -1,5 +1,8 @@ @page +@using ProductManagement +@using Volo.Abp.Settings @model PublicWebSite.Host.Pages.ProductsModel +@inject ISettingProvider SettingProvider

Our Products

\ No newline at end of file + + +@* An example to show how to read settings from the client side / UI *@ +

Maximum allowed page size: @await SettingProvider.GetOrNullAsync(ProductManagementSettings.MaxPageSize)

\ No newline at end of file diff --git a/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml.cs b/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml.cs index d82aa68175..e67ebff531 100644 --- a/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml.cs +++ b/samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using MyCompanyName.ProductManagement; using ProductManagement; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/IPublicProductAppService.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/IPublicProductAppService.cs index 00934075e9..b47e61fb02 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/IPublicProductAppService.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/IPublicProductAppService.cs @@ -1,9 +1,8 @@ using System.Threading.Tasks; -using ProductManagement; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; -namespace MyCompanyName.ProductManagement +namespace ProductManagement { public interface IPublicProductAppService : IApplicationService { diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementApplicationContractsModule.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementApplicationContractsModule.cs index d8697022b8..53fe58cbe0 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementApplicationContractsModule.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementApplicationContractsModule.cs @@ -3,6 +3,7 @@ using Volo.Abp.Application; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Localization; using Volo.Abp.Modularity; +using Volo.Abp.Settings; using Volo.Abp.VirtualFileSystem; namespace ProductManagement @@ -31,6 +32,11 @@ namespace ProductManagement .Get() .AddVirtualJson("/ProductManagement/Localization/ApplicationContracts"); }); + + Configure(options => + { + options.DefinitionProviders.Add(); + }); } } } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettingDefinitionProvider.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettingDefinitionProvider.cs new file mode 100644 index 0000000000..98842127e1 --- /dev/null +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettingDefinitionProvider.cs @@ -0,0 +1,22 @@ +using Volo.Abp.Settings; + +namespace ProductManagement +{ + /* These setting definitions will be visible to clients that has a ProductManagement.Application.Contracts + * reference. Settings those should be hidden from clients should be defined in the ProductManagement.Application + * package. + */ + public class ProductManagementSettingDefinitionProvider : SettingDefinitionProvider + { + public override void Define(ISettingDefinitionContext context) + { + context.Add( + new SettingDefinition( + ProductManagementSettings.MaxPageSize, + "100", + isVisibleToClients: true + ) + ); + } + } +} \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettings.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettings.cs new file mode 100644 index 0000000000..da420547d0 --- /dev/null +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettings.cs @@ -0,0 +1,12 @@ +namespace ProductManagement +{ + public static class ProductManagementSettings + { + public const string GroupName = "ProductManagement"; + + /// + /// Maximum allowed page size for paged list requests. + /// + public const string MaxPageSize = GroupName + ".MaxPageSize"; + } +} \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs index e11eac435f..90d16ec7b5 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs @@ -2,10 +2,8 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; -using ProductManagement; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; -using Volo.Abp.Domain.Repositories; namespace ProductManagement { @@ -23,6 +21,8 @@ namespace ProductManagement public async Task> GetListPagedAsync(PagedAndSortedResultRequestDto input) { + await NormalizeMaxResultCountAsync(input); + var products = await _productRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount); var totalCount = await _productRepository.GetCountAsync(); @@ -32,7 +32,7 @@ namespace ProductManagement return new PagedResultDto(totalCount, dtos); } - public async Task> GetListAsync() + public async Task> GetListAsync() //TODO: Why there are two GetList. GetListPagedAsync would be enough (rename it to GetList)! { var products = await _productRepository.GetListAsync(); @@ -73,5 +73,14 @@ namespace ProductManagement { await _productRepository.DeleteAsync(id); } + + private async Task NormalizeMaxResultCountAsync(PagedAndSortedResultRequestDto input) + { + var maxPageSize = (await SettingProvider.GetOrNullAsync(ProductManagementSettings.MaxPageSize))?.To(); + if (maxPageSize.HasValue && input.MaxResultCount > maxPageSize.Value) + { + input.MaxResultCount = maxPageSize.Value; + } + } } } \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementApplicationModule.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementApplicationModule.cs index 999f6385ca..4816844d93 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementApplicationModule.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementApplicationModule.cs @@ -1,6 +1,5 @@ using Volo.Abp.AutoMapper; using Volo.Abp.Modularity; -using Volo.Abp.Settings; namespace ProductManagement { @@ -17,11 +16,6 @@ namespace ProductManagement { options.AddProfile(validate: true); }); - - Configure(options => - { - options.DefinitionProviders.Add(); - }); } } } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettingDefinitionProvider.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettingDefinitionProvider.cs deleted file mode 100644 index 168e441945..0000000000 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettingDefinitionProvider.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Volo.Abp.Settings; - -namespace ProductManagement -{ - public class ProductManagementSettingDefinitionProvider : SettingDefinitionProvider - { - public override void Define(ISettingDefinitionContext context) - { - /* Define module settings here. - * Use names from ProductManagementSettings class. - */ - } - } -} \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettings.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettings.cs deleted file mode 100644 index 19ca732df8..0000000000 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettings.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace ProductManagement -{ - public static class ProductManagementSettings - { - public const string GroupName = "ProductManagement"; - - /* Add constants for setting names. Example: - * public const string MySettingName = GroupName + ".MySettingName"; - */ - } -} \ No newline at end of file diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/PublicProductAppService.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/PublicProductAppService.cs index 3305704ff9..866cc31b34 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/PublicProductAppService.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/PublicProductAppService.cs @@ -1,10 +1,9 @@ using System.Collections.Generic; using System.Threading.Tasks; -using ProductManagement; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; -namespace MyCompanyName.ProductManagement +namespace ProductManagement { public class PublicProductAppService : ApplicationService, IPublicProductAppService {