示例#1
0
        public NewProductEventProcessor(
            ILogger <NewProductEventProcessor> logger,
            IEventSubscriber eventSubscriber,
            IProductRepository productRepository,
            IProductCache productCache
            )
        {
            this.logger     = logger;
            this.subscriber = eventSubscriber;
            this.subscriber.ProductAddedEventReceived += (prd) => {
                //if (prd?.Product != null)
                //{
                //    productRepository.AddProduct(prd.Product);
                //    productCache.Put(prd.Product);
                //}
                //else if (prd?.Catagory != null)
                //{
                //    productRepository.AddCatagory(prd.Catagory);
                //}

                var product = new Product()
                {
                    ProductName = prd.ProductName,
                    ProductId   = prd.ProductId,
                    Description = prd.Description,
                    Price       = prd.Price,
                    CatagoryId  = prd.CatagoryId,
                };
                productRepository.AddProduct(product);
                productRepository.AddCatagory(
                    new Catagory
                {
                    CatagoryId   = prd.CatagoryId,
                    CatagoryCode = prd.CatagoryCode,
                    CatagoryDesc = prd.CatagoryDesc,
                    CatagoryName = prd.CatagoryName
                });

                productCache.Put(product);
            };
        }
示例#2
0
        public NewProductEventProcessor(
            ILogger <NewProductEventProcessor> logger,
            IEventSubscriber eventSubscriber,
            IProductRepository productRepository,
            IProductCache productCache
            )
        {
            this.logger     = logger;
            this.subscriber = eventSubscriber;
            this.subscriber.ProductAddedEventReceived += (prd) => {
                var newProduct = new Product
                {
                    Name      = prd.Name,
                    ProductId = prd.ProductId,
                    Category  = prd.Category
                };
                productRepository.Add(newProduct);

                productCache.Put(newProduct);
            };
        }