doupu9251 2015-01-21 14:15
浏览 37

包含来自多个有界上下文的数据的对象列表

First of all, I'm quite new in DDD, so I may get some concepts wrong.

The problem I'm facing in is as follows:

I have a list of tickets for some processing system. The tickets are based on a data from external sources crawled / tracked by Crawlin System.

Obviously, these two are separate Bounded Contexts. As for now I'm quite certain, that my boundaries are correct here, as they have little to none common points (ticket is connected to an external source, but they are processed and updated separately and in different ways).

Now, I want to create a ticket list with all tickets. Each ticket has some data from one bounded context (available actions etc) and some data from another (graphical representation of external data).

I already know, that to avoid data duplication I may use a composite view of each ticket, where each bounded context renders its own UI parts. I've seen Amazon site decomposition. Let's also assume, that my templating framework allows me to use blocks, or components to compose the ticket view.

The problem

I'm struggling with a method of retrieving these views / UI parts in an application without too many queries. I don't want to make one request for each component to avoid N+1 query hell (even if those queries are on some NoSQL cache). I imagine, that my view controller somehow asks both bounded contexts to provide a list of controls and then renders them (e.g one to retrieve a list of tickets based on search criteria and other to retrieve external content based on a list of external content IDs). But I'm not sure if I'm on a right track.

Code examples in any language (pseudo language) are much appreciated.

  • 写回答

1条回答 默认 最新

  • dongweizhen2009 2015-01-21 21:41
    关注

    I think you are on right track.

    Just as you wrote, you can create some sort of view model (view entity) for this with a service that would query one source and second (external) source just once. Then it would merge them into single view models which will be passed onto the UI layer.

    This way you also keep the logic of data merging in the domain layer. In the presentation layer you would work with them just as normal view models (entities) - without leaking the information such as their source, how to merge them etc.

    Once in the domain layer, you can add local caching too (if required).

    <?php
    
    class ViewTicketProvider
    {
        private $externalService;
    
        public function __construct(ExternalProviderInterface $externalService)
        {
            $this->externalService = $externalService;
        }
    
        public function getViewTickets(Collection $tickets)
        {
            $ids = $tickets->getIds();
    
            $externalEntities = $this->externalService->getByIds($ids);
    
            $viewTickets = array();
    
            foreach ($tickets as $ticket) {
                $viewTicket = new ViewTicket($ticket);
                // If this is too complex, use another service for the merging.
                $viewTicket->addMoreInfoFromExternalSource($externalEntities);
    
                $viewTickets[] = $viewTicket;
            }
    
            return $viewTickets;
        }
    }
    
    
    $ticketRepo      = new TicketRepository();
    $externalService = new ExternalService();
    
    $tickets = $ticketRepo->getTicketsBasedOnSomeCriteria($criteria);
    
    $viewTicketProvider = new ViewTicketProvider($externalService);
    $viewTickets = $viewTicketProvider->getViewTickets($tickets);
    
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法