Browse Source

Add a simple setting example.

pull/818/head
Halil ibrahim Kalkan 7 years ago
parent
commit
34f68c27c4
  1. 8
      samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml
  2. 1
      samples/MicroserviceDemo/applications/PublicWebSite.Host/Pages/Products.cshtml.cs
  3. 3
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/IPublicProductAppService.cs
  4. 6
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementApplicationContractsModule.cs
  5. 22
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettingDefinitionProvider.cs
  6. 12
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/ProductManagement/ProductManagementSettings.cs
  7. 15
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs
  8. 6
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementApplicationModule.cs
  9. 14
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettingDefinitionProvider.cs
  10. 11
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettings.cs
  11. 3
      samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/PublicProductAppService.cs

8
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
<h1>Our Products</h1>
<ul>
@foreach (var product in Model.Products.Items)
@ -9,4 +12,7 @@
<i>Stock count: @product.StockCount</i>
</li>
}
</ul>
</ul>
@* An example to show how to read settings from the client side / UI *@
<p><i>Maximum allowed page size: @await SettingProvider.GetOrNullAsync(ProductManagementSettings.MaxPageSize)</i></p>

1
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;

3
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
{

6
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<ProductManagementResource>()
.AddVirtualJson("/ProductManagement/Localization/ApplicationContracts");
});
Configure<SettingOptions>(options =>
{
options.DefinitionProviders.Add<ProductManagementSettingDefinitionProvider>();
});
}
}
}

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

12
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";
/// <summary>
/// Maximum allowed page size for paged list requests.
/// </summary>
public const string MaxPageSize = GroupName + ".MaxPageSize";
}
}

15
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<PagedResultDto<ProductDto>> 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<ProductDto>(totalCount, dtos);
}
public async Task<ListResultDto<ProductDto>> GetListAsync()
public async Task<ListResultDto<ProductDto>> 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<int>();
if (maxPageSize.HasValue && input.MaxResultCount > maxPageSize.Value)
{
input.MaxResultCount = maxPageSize.Value;
}
}
}
}

6
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<ProductManagementApplicationAutoMapperProfile>(validate: true);
});
Configure<SettingOptions>(options =>
{
options.DefinitionProviders.Add<ProductManagementSettingDefinitionProvider>();
});
}
}
}

14
samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettingDefinitionProvider.cs

@ -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.
*/
}
}
}

11
samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductManagementSettings.cs

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

3
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
{

Loading…
Cancel
Save