IEnumerable and Datareader extension method, suggestions needed
<p>following is the extension method to convert a datareader to the an object using OMU value injector based "DataReaderInjection" class.</p>

<pre><code>public static IEnumerable&lt;T&gt; MapTo&lt;T&gt;(this IDataReader reader) where T : new() {
    return reader.MapTo&lt;T&gt;(null);
}

public static IEnumerable&lt;T&gt; MapTo&lt;T&gt;(this IDataReader reader, Action&lt;IDataReader, T&gt; customMappingFunction) where T : new() {
    using (reader)
        while (!reader.IsClosed &amp;&amp; reader.Read()) {
            var nextItem = new T();
            nextItem.InjectFrom&lt;DataReaderInjection&gt;(reader);
            if (customMappingFunction != null)
                customMappingFunction(reader, nextItem);
            yield return nextItem;
        }
}
</code></pre>

<p>this method has a bug since once you call this method and datareader is closed, next call would return an empty IEnumerable,To fix this I changed above code to following.</p>

<pre><code>public static class DataAccessExtensions
{
    public static IEnumerable&lt;T&gt; MapTo&lt;T&gt;(this IDataReader reader) where T : new() {
        return reader.MapTo&lt;T&gt;(null);
    }

    private static Dictionary&lt;int, IEnumerable&gt; dataReaderCache = new Dictionary&lt;int, IEnumerable&gt;();
    private static object lockObj = new object();

    public static IEnumerable&lt;T&gt; MapTo&lt;T&gt;(this IDataReader reader, Action&lt;IDataReader, T&gt; customMappingFunction) where T : new() {
        lock (lockObj)
        {
            if (dataReaderCache.ContainsKey(reader.GetHashCode()))
                return dataReaderCache[reader.GetHashCode()] as IEnumerable&lt;T&gt;;
        }
        List&lt;T&gt; finalList = new List&lt;T&gt;();
        using (reader) {
            while (!reader.IsClosed &amp;&amp; reader.Read()) {
                var nextItem = new T();
                nextItem
                    .InjectFrom&lt;DataReaderInjection&gt;(reader);
                if (customMappingFunction != null)
                    customMappingFunction(reader, nextItem);
                finalList.Add(nextItem);
            }
        }
        lock (lockObj)
        {
            dataReaderCache.Add(reader.GetHashCode(), finalList);
        }
        return finalList;
    }
</code></pre>

<p>}</p>

<p>What do you guys think will this work</p>
