Example #1
0
        protected virtual void GetByIdOnThread <TId>(TId id, ModelReturnCallback callback)
        {
            ISession currentSession = Decorated.Session;

            Decorated.Session = Session;
            callback(Decorated.GetById <TId>(id));
            Decorated.Session = currentSession;
        }
Example #2
0
        /// <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;
     }
 }
Example #4
0
 public virtual TModel GetById <TId>(TId id)
 {
     return(Decorated.GetById <TId>(id));
 }