public IPersistent <TEntity> GetObject <TEntity>(string objectId) where TEntity : Entity, new() { Persistent persistent; if (objects.TryGetValue(objectId, out persistent)) { var castObj = persistent as Persistent <TEntity>; if (castObj == null) { var type = persistent.GetType(); throw new InvalidOperationException( string.Format( "Previously resolved Persistent<T> is of entity type different than requested, requested type: {0}, actual type: {1}", typeof(Persistent <TEntity>).FullName, type.FullName)); } return(castObj); } Persistent <TEntity> obj = null; bool retry; int currentRetry = 0; int retryMax = 100; do { var resolver = new ObjectResolver <TEntity>(objectId, collectionId, persistenceStrategy, serializationStrategy, deserializationErrorHandlingStrategy); try { obj = resolver.GetObject(); retry = false; } catch (RetryException) { if (retryMax == currentRetry) { throw new InvalidOperationException(string.Format("Maximum retry count reached ({0})", retryMax)); } retry = true; currentRetry++; } } while (retry); objects.Add(objectId, obj); return(obj); }