注:此处的微服务只考虑服务部分,不考虑内外层网关、认证等。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,望技术有成后能回来看见本身的脚步