public async Task <Response <FileConfiguration> > Get() { var fileConfiguration = new FileConfiguration(); var globalConfiguration = await _globalConfigurationAppService.GetAsync(); fileConfiguration.GlobalConfiguration = _objectMapper.Map <GlobalConfigurationDto, FileGlobalConfiguration>(globalConfiguration); var reRouteConfiguration = await _reRouteAppService.GetListAsync(); if (reRouteConfiguration != null && reRouteConfiguration.Items.Count > 0) { foreach (var reRouteConfig in reRouteConfiguration.Items) { fileConfiguration.ReRoutes.Add(_objectMapper.Map <ReRouteDto, FileReRoute>(reRouteConfig)); } } var dynamicReRouteConfiguration = await _dynamicReRouteAppService.GetListAsync(); if (dynamicReRouteConfiguration != null && dynamicReRouteConfiguration.Items.Count > 0) { foreach (var dynamicRouteConfig in dynamicReRouteConfiguration.Items) { fileConfiguration.DynamicReRoutes.Add(_objectMapper.Map <DynamicReRouteDto, FileDynamicReRoute>(dynamicRouteConfig)); } } return(new OkResponse <FileConfiguration>(fileConfiguration)); }
public async Task <IActionResult> Source() { var globalConfig = await _globalConfigurationAppService.GetAsync(); var reRouteConfig = await _reRouteAppService.GetListAsync(); var dynamicConfig = await _dynamicReRouteAppService.GetListAsync(); var aggregateConfig = await _aggregateReRouteAppService.GetListAsync(); // 这是个弊端,以后如果Ocelot的配置属性变更 // Admin程序随之需要变更实体、Dto、Model三个地方 // 其他解决办法 Emit? // 如果直接引用Ocelot即可解决,但是在Admin中引用它违反了设计结构 var ocelotConfigurationDto = new OcelotConfigurationModel { GlobalConfiguration = ObjectMapper.Map <GlobalConfigurationDto, GlobalConfigurationModel>(globalConfig), ReRoutes = ObjectMapper.Map <List <ReRouteDto>, List <ReRouteModel> >(reRouteConfig.Items.ToList()), DynamicReRoutes = ObjectMapper.Map <List <DynamicReRouteDto>, List <DynamicReRouteModel> >(dynamicConfig.Items.ToList()), Aggregates = ObjectMapper.Map <List <AggregateReRouteDto>, List <AggregateReRouteModel> >(aggregateConfig.Items.ToList()) }; return(View(ocelotConfigurationDto)); }