注:此處的微服務只考慮服務部分,不考慮內外層網關、認證等。git
ABP VNext從單體切換到微服務,提供了至關大的便利性,對於各模塊內部不要作任何調整,僅須要調整承載體便可。c#
ABP can help you in that point by offerring a microservice-compatible, strict module architecture where your module is splitted into multiple layers/projects and developed in its own VS solution completely isolated and independent from other modules. Such a developed module is a natural microservice yet it can be easily plugged-in a monolithic application.api
清理以後變得簡簡單單的。架構
對於test內部,一樣採起剔除無需的HttpApi.CLient、MongoDB文件夾(注:此處的無需只是針對我而言,若是有須要仍是留着吧)。app
清理以後,層次劃分變得簡簡單單的。async
public interface IProductServiceClient : ITransientDependency { Task<int> GetProductId(); }
public class ProductServiceClient : IProductServiceClient { private readonly IProductAppService _productAppService; public ProductServiceClient(IProductAppService productAppService) { _productAppService = productAppService; } public async Task<int> GetProductId() { var productDto = await _productAppService.GetAsync(); return productDto.Value; } }
public class OrderAppService : OrderManagementAppService, IOrderAppService { private readonly IProductServiceClient _productServiceClient; public OrderAppService(IProductServiceClient productServiceClient) { _productServiceClient = productServiceClient; } public async Task<OrderDto> GetAsync() { var productId = await _productServiceClient.GetProductId(); ... } }
將依照以下圖,將三個模塊承載到GravelService.Host上。ide
[DependsOn( typeof(AbpAutofacModule), typeof(AbpAspNetCoreMvcModule), typeof(AbpAspNetCoreMultiTenancyModule), typeof(CustomerManagementApplicationModule), typeof(CustomerManagementEntityFrameworkCoreModule), typeof(OrderManagementApplicationModule), typeof(OrderManagementEntityFrameworkCoreModule), typeof(ProductManagementApplicationModule), typeof(ProductManagementEntityFrameworkCoreModule) )] public class GravelServiceHostModule : AbpModule { ... }
Configure<AbpAspNetCoreMvcOptions>(options => { options.ConventionalControllers .Create(typeof(CustomerManagementApplicationModule).Assembly, opts => { opts.RootPath = "CustomerManagement"; }) .Create(typeof(OrderManagementApplicationModule).Assembly, opts => { opts.RootPath = "OrderManagement"; }) .Create(typeof(ProductManagementApplicationModule).Assembly, opts => { opts.RootPath = "ProductManagement"; }); });
此時是在同一進程內,使用到的是ProductAppService的具體實現,斷點查看也可看出當前進程內的請求,依賴其餘上下文服務的應用服務爲ApplicationServiceProxy。模塊化
依照以下圖開始切換承載模式,只更改承載體,將一個大的承載體切分紅各上下文獨自承載體。微服務
[DependsOn( typeof(AbpAutofacModule), typeof(AbpAspNetCoreMvcModule), typeof(AbpAspNetCoreMultiTenancyModule), typeof(OrderManagementApplicationModule), typeof(OrderManagementEntityFrameworkCoreModule), typeof(ProductManagementApplicationContractsModule) )] public class OrderServiceHostModule : AbpModule { ... }
[DependsOn( ... typeof(AbpHttpClientModule), ... )] public class OrderServiceHostModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); ... context.Services.AddHttpClientProxies( typeof(ProductManagementApplicationContractsModule).Assembly); ... } }
{ "RemoteServices": { "Default": { "BaseUrl": "http://localhost:57687" } }
從大單體承載切換多服務承載,Modules部分不須要作任何更改,着實方便。至於內部的遠程調用,自己ABP VNext還存在一些問題像相似集合的Get請求在3.1的版本中才作了修復,可是這絲絕不影響這一巨人的前行。命令行
2020-09-26,望技術有成後能回來看見本身的腳步