Beispiel #1
0
        public Product Execute(GetProductUseCaseRequest request)
        {
            // Since request is a ValueObject it can be used as a cacheKey
            // if it was a normal object this would never hit the cache
            return(_cache.GetOrCreate(request, cacheEntry =>
            {
                cacheEntry.SetOptions(_cacheOptions);

                return _innerUseCase.Execute(request);
            }));
        }
Beispiel #2
0
        public Product Execute(GetProductUseCaseRequest request)
        {
            Thread.Sleep(1000); //Fake delay to show caching benefits

            if (request.Id.HasValue ^ string.IsNullOrEmpty(request.Name))
            {
                throw new DomainException("Request must have either ID or name.");
            }

            if (request.Id.HasValue)
            {
                return(GetById(request.Id.Value));
            }
            else
            {
                return(GetByName(request.Name));
            }
        }