protected virtual void GetByIdOnThread <TId>(TId id, ModelReturnCallback callback) { ISession currentSession = Decorated.Session; Decorated.Session = Session; callback(Decorated.GetById <TId>(id)); Decorated.Session = currentSession; }
/// <summary> /// Gets a single instance of T matching the given Id from the cache, or via the decorated method if not already cached. /// If not already cached, the entity retrieved is cached. /// </summary> /// <param name="guid">The globally unique identifier for the entity.</param> /// <returns>An asynchronous <see cref="Task{T}"/> containing the entity if found, otherwise null.</returns> public async Task <T> GetById(Guid guid) { var entity = await MemoryCache.GetOrCreateAsync(guid, async entry => { entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5); // TODO - put magic number into config return(await Decorated.GetById(guid).ConfigureAwait(false)); }).ConfigureAwait(false); return(Mapper.Map <T, T>(entity)); }
public async Task <TEntity> GetById(Guid id) { try { Log.LogDebug("Trying to fetch entity of {EntityType} with id '{Id}'", typeof(TEntity).Name, id); return(await Decorated.GetById(id)); } catch (Exception e) { Log.LogError(e, "Exception when fetching entity with id '{Id}'", id); throw; } }
public virtual TModel GetById <TId>(TId id) { return(Decorated.GetById <TId>(id)); }