// Handle cacheing of object on instantiation private void OnObjectCreation(Stock stock, IStockEntity stockEntity) { if (!stockCache.ContainsValue(stockEntity)) { stockCache.Add(stock, stockEntity); } }
public Stock Convert(IStockEntity stockEntity, IStockConverter.OnObjectCreation onObjectCreation) { Stock stock = domainFactory.CreateStock(stockEntity.Id, stockEntity.ProductId, stockEntity.Amount, stockEntity.Date, repositoryFactory.ProductsRepository.Get(stockEntity.ProductId)); // trigger cache on instantiation to prevent looping. onObjectCreation(stock, stockEntity); return(stock); }